正则表达式,用于以dd-Mmm-yyyy格式验证日期 [英] Regex for validating date in dd-Mmm-yyyy format

查看:117
本文介绍了正则表达式,用于以dd-Mmm-yyyy格式验证日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本输入框,需要验证.用户应该只能以dd-Mmm-yyyy格式输入日期.例如:2013年6月1日,2015年8月31日,依此类推.或者他们应该能够输入T + 1,T + 2,... T + 99.

I have an text input box which needs to be validated. The user should be only able to enter the date in dd-Mmm-yyyy format. ex: 01-Jun-2013, 31-Aug-2015 and so on. Or they should be able to enter T+1, T+2,...T+99.

我可以使用哪种正则表达式模式来验证这两种模式.我认为,为了验证dd-Mmnm-yyyy,以下正则表达式有效:

What kind of a regex pattern I could use to validate both of these. I think for validating the dd-Mmnm-yyyy, the following regex works:

^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$

请帮助我!

更新:我只需要单个字母T后跟"+"和范围从"1到99"的正则表达式模式.即[T + 1 ... T + 99].用户应该只能在文本字段中输入这些数字.

Update: I just need the regex pattern for a single letter T followed by "+" and a number ranging from "1 to 99". i.e., [T+1... T+99]. The user should be only able to enter these numbers into the text field.

推荐答案

T后跟​​ +",数字范围从"1到99"

T followed by "+" and a number ranging from "1 to 99"

尝试使用: T \ +?\ d {0,2} 其中:

  1. T 文字"T";
  2. \ +?-零或一个带有转义反斜杠的加号"+"(或其他转义字符,取决于语言)-如果没有,它将被视为元字符'+';额外的?"唱歌的意思是,该字符之前可能会出现,但这不是必需的
  3. \ d {0,2} -从零到两位数字;
  1. T literal "T";
  2. \+? - zero or one plus sign "+" with escape backslash (or other escape character, depends on language) - without it it will be treated as metacharacter '+'; the additional '?' sing means, that character before that could appear, but it is not necessary
  3. \d{0,2} - from zero to two digits;

演示

这篇关于正则表达式,用于以dd-Mmm-yyyy格式验证日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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