0

i tried multiple examples to validate a string in textbox but could not get right answer.

  1. first digit could be +,-,decimal point,any number. but all symbols should not repeat e.g ++ is invalid but 00 is valid 2.after decimal it should allow only upto two digits but if user does not enters it should accept it. after decimal if user just enters 1 numeric digit that should be also fine e.g 1.1 and 1.23 and .3, and .43 all are valid but 11. and 11.. are not valid

some examples for valid and invalid valid 1,1.0,.4,.45,+1,-2,-.3,-1.2,+.23,-.6,2.45 all are valid invalid ++,1.234,.,1.+,2.300,...etc

1 Answer 1

1

Your regex would be,

^[+-]?\d*(?:\.\d{1,2})?$

DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.