Saturday, April 24, 2010

Simple Float / Double validation using regex

This is a simple regex expression to validate a float/double value.

" on the start and end of the below regex is not part of the expression.

Expression : "\\d*\\.\\d+"

pass - 23.45 , .3
fail - 23. , .


In the above expression the part \\d* denotes zero or more digits.\\d is to represent digit and * for zero or more. The next one \\. is for the dot character. And finally \\d+ for at least one or more digits. Here + is for one or more.

No comments:

Post a Comment