简体   繁体   中英

Regular expression javascript how to write 4 digits followed by an exclamation mark "4444!"

I tired to write a regular expression where regular expression match 4 digits and follow by exclamation mark as in "4444!"

this is what I got so far

function checkAcc(acc){
    regx = /^\d{4}$(?=!)/
    return regx.test(acc)
}

I tired and 4 digits part work but can't get the exclamation mark to work.

thank you very much for your time answer this~

Try this one:

regx = /^\d{4}(?=!$)/

Or, this one, if you do not have any plan to capture the matching.

regx = /^\d{4}!$/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM