regex - Regular Expression with .net -
i encounter in regular expression validation numbers, asp.net. want limit mamimum total digit counts 5. , decimal numbers 2 positions maximum, cannot exceed 2 digits, need valid total word count not large 5.
eg. valid numbers 12345 1234.5 123.45 0.12 invalid numbers 1.2345 ( decimal digit 4. , validation fail because decimal digits more 2 ) 1.234 , 12.345 ( decimal digit 3. , validation fail because decimal digits more 2 )
i've tried:
string regnumeric = @"^([0-9]{0,5})(\.[0-9]{0,5})?$";
but i've observed doesn't match need. check count before , count after decimal point can 0 5. doesn't include checking total number of digits. have no idea how it
your first problem \.[0-9]{0,5}
says can have 5 decimal digits, want 2. if want shorter regex use
^([0-9]{0,5})(\.[0-9]{0,2})?$
then check result make sure length under 5
Comments
Post a Comment