Condition to call masquerade!

0

How can I do to read the first character entered in the input and the part of the condition to be called a specific mask.

if(Se o primeiro caractere no input for letra){



}else{

$('#login_username').mask('(99) 9999-9999?9').focusout(function() {
	        var phone, element;
	        element = $(this);
	        element.unmask();
	        phone = element.val().replace(/\D/g, '');
	        if( phone.substring(0, 1) === '0' ) {
	            element.mask("9999-999-9999");
	        } else if (phone.length > 10) {
	            element.mask("(99) 99999-999?9");
	        } else {
	            element.mask("(99) 9999-9999?9");
	        }
	    }).trigger('focusout');
}
    
asked by anonymous 03.02.2017 / 17:10

1 answer

2

You can use regex with the script xregexp .

Then just match the expression \p{L} . If it returns, it is true, and it passes in the condition.

- Edited

Try this:

if (!isNaN(str.charAt(0))) // * charAt(0) é a primeiro char. verifica se ele não é um "Not-a-Number" - ou seja, um caractere válido para você.
    
03.02.2017 / 17:21