Regular expressions (Perl regex) for validation

I’m trying to make a validation for a custom field and obviously I’m missing
something.

The user has to enter in this custom field:
-either nothing
-either a number of exactly 2 digits

I’m ok with the “exactly 2 digits”: (?#2 digits. E.g.:01,11,12)^\d{2}$
but don’t know how to add the possibility of entering nothing.

Someone has the answer ?

Thanks.

GH

View this message in context: http://requesttracker.8502.n7.nabble.com/Regular-expressions-Perl-regex-for-validation-tp58667.html

I’m trying to make a validation for a custom field and obviously I’m
missing something.

In this custom field, the user has to enter:
-either nothing
-either a number of exactly 2 digits

I’m ok with the “exactly 2 digits”: (?#2 digits. E.g.:01,11,12)^\d{2}$
but don’t know how to add the possibility of entering nothing.

Someone has the answer ?

Thanks.

GH

In this custom field, the user has to enter:�
� -either nothing�
� -either a number of exactly 2 digits�

if you use the x modifier:

(
    # Nothing 
|   
    \d{2} # two digits
)

the old school one is

(|\d{2}) 

HTH

Marc Chantreux,
Mes coordonn�es: Annuaire - Université de Strasbourg
Direction Informatique, Universit� de Strasbourg (http://unistra.fr)
Service M�tiers, P�le Outils Collaboratifs
“Don’t believe everything you read on the Internet”
– Abraham Lincoln

Thank you Marc for the final answer: ^(|\d{2})$

GH

View this message in context: http://requesttracker.8502.n7.nabble.com/Regular-expressions-Perl-regex-for-validation-tp58668p58672.html

For those who have the same question (or similar), Marc provided the
correct answer in my context: ^(|\d{2})$

Thank you Marc

GH2014-09-30 10:13 GMT-04:00 Marc Chantreux mc@unistra.fr:

On Tue, Sep 30, 2014 at 09:18:37AM -0400, Gaston Huot wrote:

In this custom field, the user has to enter:
-either nothing
-either a number of exactly 2 digits

if you use the x modifier:

(
    # Nothing
|
    \d{2} # two digits
)

the old school one is

(|\d{2})

HTH


Marc Chantreux,
Mes coordonnées: Annuaire - Université de Strasbourg
Direction Informatique, Université de Strasbourg (http://unistra.fr)
Service Métiers, Pôle Outils Collaboratifs
“Don’t believe everything you read on the Internet”
– Abraham Lincoln

Gaston
514.823-7202