Вопрос

How do I automatically insert a hyphen in my input postal code form?

Postal Code example: 00000 - 000 Phone number example: 5555 - 5555

I need it to be formatted without having to typing the hyphen in it.

I appreciate any help!

Это было полезно?

Решение

Try this for postal

$("input .postal").blur( function() {
   $(this).val( number.replace(/^(\d{5})(\d{3})$/, '$1-$2') );
}); 

and this for phone

$("input .phone").blur( function() {
   $(this).val( number.replace(/^(\d{4})(\d{4})$/, '$1 - $2') );
}); 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top