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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -