Asp.net validation C# Date and decimal

Angela4eva
Angela4eva used Ask the Experts™
on
I need help to do validation i need to make sure that user has entered correct value in text in decimal format x.xx  if empty ignore and there is another textbox which i want to make sure that user has entered a valid date if empty ignore
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can use regular expressions.

"^[+]?[0-9]+[.]?[0-9]*([-+]?[0-9]+)?$" will allow positive numbers asmany as you want before and after the decimal. Only one decimal.

you can use it in something similar to my example below
Regex number = new Regex("^[+]?[0-9]+[.]?[0-9]*([-+]?[0-9]+)?$");

            if (userTextBox != "")
            {
                if (number.IsMatch(userTextBox))
                {
                    //so some stuff
                }

Open in new window

Commented:
I'd also suggest using the ASP.NET Regular Expression validator:
http://msdn.microsoft.com/en-us/library/ms998267.aspx

Currency regular expression: ^\d+(\.\d\d)?$
Date regular expression: (0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial