Click here to Skip to main content
15,917,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to validate a textbox field that should accept first char as + or - and followed by decimal value

Ex: +248.58 or -528.88



I did a validation ^([-+]+(\d{1,10})(\.\d{2,2})?)+$

but this is accepting +++248.58 or ------528.88

only first char must be + or - from second char it must accept only numbers. Please do help me.

What I have tried:

^([-+]+(\d{1,10})(\.\d{2,2})?)+$
Posted
Updated 24-Feb-16 21:16pm
v2

1 solution

That's becasue you told it to!
[-+]+
is Regex for "a '-' or '+' character, at least one, but as many as wanted.
Take out the repitition indicator and it should work:
^([-+](\d{1,10})(\.\d{2,2})?)+$

If you are going to work with Regular Expressions, then get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
[edit]I HATE MARKDOWN! Even when it's turned off, and inside a code block, it manages to muck up strings... :mad: [/edit]
 
Share this answer
 
v4
Comments
Member 11261355 25-Feb-16 4:06am    
it works!!! thank you
OriginalGriff 25-Feb-16 4:13am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900