Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('#phone').keydown(function (e) {
- if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
- // Allow: Ctrl+A
- (e.keyCode == 65 && e.ctrlKey === true) ||
- // Allow: Ctrl+C
- (e.keyCode == 67 && e.ctrlKey === true) ||
- // Allow: Ctrl+X
- (e.keyCode == 88 && e.ctrlKey === true) ||
- // Allow: home, end, left, right
- (e.keyCode >= 35 && e.keyCode <= 39)) {
- // let it happen, don't do anything
- return;
- }
- // Ensure that it is a number and stop the keypress
- if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
- e.preventDefault();
- }
- var foo = $(this).val().split("-").join(""); // remove hyphens
- foo = foo.match(new RegExp('.{1,4}$|.{1,3}', 'g')).join("-");
- $(this).val(foo);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement