验证月份格式 [英] Validate Month Year Format
本文介绍了验证月份格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要验证这种格式的文本框(例如:FEB 2014 MMM YYYY)。
I need to validate Text box in this format (ex:FEB 2014 MMM YYYY).
我正在使用以下正则表达式字符串
I am using the following regular expression string
^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\-\d{4}$
唯一的问题是我的输入带有'空格'而不是'-'即2012年6月而不是2012年6月
Only issue is that my input is with a 'space' and not '-' i.e. JUN 2012 not JUN-2012
有人可以修改上述正则表达式来满足空间需求
Can someone please amend the above regex to cater for space
谢谢
推荐答案
使用 \s
而不是 \ -
在正则表达式中
use \s
instead of \-
in your regex
像这样:
^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\s\d{4}$
@Avinash是正确的比赛 [\r\n\t\f]
最好改用。
@Avinash is right \s matches [\r\n\t\f]
better use " " instead.
这篇关于验证月份格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文