AndreDuarte
AndreDuarte

Reputation: 804

Validate phone field with javascript without using onblur

I have a problem that's probably simple but i cannot change the moment of the validation.

There is a phone field with a mask that accepts 8 digits:

$(idDDDTelefone).mask('99999999', {
    placeholder : " "
});

But a recent change on phone system added a 9 digit on some numbers. I cannot just change the mask to 9 digits cause it wont accept 8 digits phone numbers. How can I do this? Theres any minlenght function?

Upvotes: 0

Views: 377

Answers (1)

Liam
Liam

Reputation: 2837

You could use the optional character after the 8th digit.

$('.phone').mask('99999999Z', {translation:  {'Z': {pattern: /[0-9]/, optional: true}}});

Upvotes: 3

Related Questions