c# - Regex to match a doubles separated by one space only -


i trying check match user enters values in text box.

valid values textbox this:

"-"  "-5.5"  "-5.5 6.5 7.5" 

invalid be

"-5.5   6.5    " 

edit: ^there more 1 space between -5.5 , 6.5, doesn't show reason.

"3.5 "  ^(-?)(\d+\.?\d?)\s?(-?\d+\.?\d?) 

keep in mind negative sign special character, other decimal point, allowed in here.

thanks.

i think you're looking for:

^(-|-?\d+\.?\d?([ ]-?\d+\.?\d?)*)$ 

this match either single hyphen or number of space-separated positive or negative numbers optional decimal point , @ 1 digit after it. allow values "5.5 6.5" or "-5.5 -6.5" (your question didn't specify if should match or not)

you can test here.


update

this allow many more matches, satisfies new requirement of supporting every valid sequence user typing. of course, allows more, since it's impossible determine difference between invalid input , input merely incomplete (e.g. -5 -).

^(-?(\d+\.?\d?( |$)|$))*$ 

you can test here.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -