Wednesday, 12 June 2013

alphanumeric characters validation regular expression


^[0-9]+(\.[0-9]{1,2})?$

regular expression for two decimal number

And since regular expressions are horrible to read, much less understand, here is the verbose equivalent:

^                   # Start of string.
[0-9]+              # Must have one or more numbers.
(                   # Begin optional group.
    \.              # The decimal point, . must be escaped,
                    # or it is treated as "any character".
    [0-9]{1,2}      # One or two numbers.
)?                  # End group, signify it's optional with ?
$                   # End of string.


Test here

 http://www.regular-expressions.info/javascriptexample.html

No comments:

Post a Comment