简体   繁体   中英

Simple JavaScript IBAN Validation

I wanted to make a really easy JavaScript validation for the IBAN. It is for a project on school what means the goal of the validation isn't to get a 100% good IBAN validation but something easy to get along with.

I tried to create my own: /^[AZ]{2}+[0-9A-Z]*$/

But apparently it seems to disactivate all the Javascript in the same file. What is the reason that this disactivates all my JavaScript, and what is a good validation?

The conditions of the validation (might it not be clear already):

  1. The first two characters must be alphabetic and upper-case.
  2. The other characters can be numeric and/or alphabetic.

The length doesn't have to be included because that is checked with another if-statement in my function.

That's because you're using two-quantifiers side-by-side

/^[A-Z]{2}+[0-9A-Z]*$/
      //  ^ Remove this. It means match the previous token one or more times

So, it would be /^[AZ]{2}[0-9A-Z]*$/

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