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.

jsfiddle demo

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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -