Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to validate field with various mask length ? #48

Open
AntonGrekov opened this issue Apr 14, 2020 · 0 comments
Open

How to validate field with various mask length ? #48

AntonGrekov opened this issue Apr 14, 2020 · 0 comments

Comments

@AntonGrekov
Copy link

I have met an issue with validation phone field that could be different length. Being not very experienced with validations i have found may be not best solution but for my situation it worked you.
May be it will help you.

So problem is that for one country mask length - 10, for another 12, for another 13 and we need to warn user to fill phone field completly.
I used this algorithm:

  1. Change inputmask initialization setting 'autoUnmask': false, so when getting input value - you get it with _ symbol
  2. Use this simpliest regexp to find if there any '_' left in input field , if so - field not completed

if (/_/.test(phoneInput.val())) {
alert('phone empy, pls enter phone');
//do any stuff u want here - shows divs erros etc
}

Little advantage over //clearIncomplete: true, is that it leaves user input to complete later

Would be glad to know correct/other ways to validate different length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant