Click here to Skip to main content
15,899,556 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi i need to use same textbox for inserting date of birth and age ie if a person knows dob he enters dob and if dob is unknown he enters age . So I need to validate my textbox using regular expression so a person can enter date in dd/mm/yyyy format or upto 3 digit age ..Please help me to validate my textbox either using regular expression or anything else
Posted
Comments
Sandeep Mewara 5-Sep-12 7:42am    
What have you tried so far?
VIPR@T 5-Sep-12 7:43am    
please show your code here
Pratika05 5-Sep-12 7:57am    
i have tried
ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"

for validating date but i also want to validate age in same expression

If you must do it like that, try this regex:
^((?<day>\d{1,2})/(?<month>\d{1,2})/(?<year>(?:\d{4}|\d{2}))|(?<age>\d{1,3}))$

But me? I'd use two controls, and a radio button. And one of the controls would be a date picker.

[Edit]System added spurious closing tags - OriginalGriff[/Edit]
 
Share this answer
 
v2
Comments
Pratika05 5-Sep-12 8:09am    
it shows error
OriginalGriff 5-Sep-12 8:18am    
What error?
If you want to learn more about Regular Expressions you should check out this site[^. To uitilize a large library of Regular Expressions go to http://regexlib.com[^]. They also have a RegEx tester[^]. Also a very useful RegEx tool is available here.
 
Share this answer
 
v2
C#
ValidationExpression="^((((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|(\d{1,3}))$"
 
Share this answer
 
v2
Comments
Pratika05 5-Sep-12 8:32am    
is my solution right
Anuja Pawar Indore 5-Sep-12 9:20am    
Use improve question and paste your code there. Don't write it as answer

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