A
A
Adex2017-09-09 01:29:18
JavaScript
Adex, 2017-09-09 01:29:18

How to combine regex validation and inputmask field?

View mask code

$('#input').inputmask({
    mask: '8 ( 999 ) 999 - 99 - 99',
    showMaskOnHover: false,
  });


Examination
function validateNum(num) { 
    var reg = /^[0-9]{20}$/;
    return reg.test(num);
  }


When the mask is turned off, the check passes, for the test I removed all third-party characters from the mask, in addition to 8 (so as not to mess with changing the expression), the check still failed.

What can you try to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adexs, 2017-09-09
@Adex

Problem solved.

M
MaximMRX, 2018-04-05
@GM_pAnda

It's been a year, maybe it will help someone. For those who use inputmask

var phone = $("input[name=OrderPhoneUser]").val();	
    
    var isValid = Inputmask.isValid(phone , { mask: '+7 (999) 999-99-99'});
    
    if(isValid){
      alert('OK');
    }else{
      alert('ERROR');
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question