出生日期验证 [英] validation for date of birth

查看:68
本文介绍了出生日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用相同的文本框来输入出生日期和年龄,即,如果一个人知道dob,他就输入dob;如果不知道dob,则他要输入年龄.因此,我需要使用正则表达式来验证我的文本框,以便一个人可以以dd/mm/yyyy格式或不超过3位数字的年龄输入日期..请使用正则表达式或其他任何方法来帮助我验证我的文本框

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

推荐答案

如果必须这样做,请尝试以下正则表达式:
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}))



除了我?我会使用两个控件和一个单选按钮.其中一个控件将是日期选择器.

[Edit]系统添加了虚假的结束标签-OriginalGriff [/Edit]


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

System added spurious closing tags - OriginalGriff[/Edit]


如果您想了解有关正则表达式的更多信息,请查看^ .要使用大型正则表达式库,请访问 http://regexlib.com [ ^ ].他们也有一个正则表达式测试仪 [<一个HREF = http://regexlib.com/(X(1)A(knbcnrG7H-2ViXlEFAAiQcn0ih9raBO1q950pBfHc0chZ_EGd-9FgwnAOtHsD5Bl-T9YJw8R_rYssQIjku8zeMf_LxfyeEqrkWrMvHv_tYxPh6Jwy2ybh472XEy-VAyj4n010hw81cwOl1Qusrd9tvzrPtxKoWZ_j5w7zXqTtpPI3J44KQZKIy25UmuFJuK10))/RETester.aspx" 目标= _空白" 标题= 新窗口"> ^ ].在此处也可以使用非常有用的RegEx工具.
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.


这篇关于出生日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆