I want to validate the value a user enters in a text box, so that it only enters float numbers. I’m not interested in range. How can I do this, considering also culture localization information (e.g. ‘.’ or ‘,’ as separators)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My usual method is to use a RegexValidator with a validation expression of
^(\d+(\.\d*)?)|(\d*(\.\d+))$. You could ammend this to enable ‘.’ or ‘,’:^(\d+([\.,]\d*)?)|(\d*([\.,]\d+))$.If you wanted to be strictly correct, you’d enable the correct validation expression for each culture.
Also note that you still need a RequiredFieldValidator if the value is compulsary.