Three Char Month and Culture matching in javascript -
i have multi cultural website, allow users enter values in dd-mmm-yyyy format. able determine different values based upon culture in c# (may, english = may, german = mai)
the problem having javascript validation of these months. able build list of acceptable values:
english:
^jan$|^feb$|^mar$|^apr$|^may$|^jun$|^jul$|^aug$|^sep$|^oct$|^nov$|^dec$
german:
^jan$|^feb$|^mrz$|^apr$|^mai$|^jun$|^jul$|^aug$|^sep$|^okt$|^nov$|^dez$
i want make regular expression case insensitive. references see pointing me /gi flag, of examples make no sense. have tried following , doesn't work:
var shouldmatch = "may"; var regexpattern = "^jan$|^feb$|^mar$|^apr$|^may$|^jun$|^jul$|^aug$|^sep$|^oct$|^nov$|^dec$/gi" if(shouldmatch.match(regexpattern) != null) { //this should happen }
what doing wrong? regex out there javascript killing me.
but trying match "mar" or "mar", etc.? becomes interesting scenario. in opinion, easy way match upper case
var shouldmatch = "may"; var regexpattern = "^jan$|^feb$|^mar$|^apr$|^may$|^jun$|^jul$|^aug$|^sep$|^oct$|^nov$|^dec$"; if(shouldmatch.touppercase().match(regexpattern) != null) { alert("match"); }
Comments
Post a Comment