Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  60] [ 1]  / answers: 1 / hits: 43454  / 11 Years ago, mon, december 16, 2013, 12:00:00

I validate the phone number using below code its working fine but i allow char at first time while user entering the values. how i can solve it. . . .



$('.Number').keypress(function () {
$('.Number').keypress(function (event) {
var keycode;

keycode = event.keyCode ? event.keyCode : event.which;

if (!(event.shiftKey == false && (keycode == 46 || keycode == 8 ||
keycode == 37 ||keycode == 39 || (keycode >= 48 && keycode <= 57)))) {
event.preventDefault();
}
});
});

More From » jquery

 Answers
1

The first character is unrestricted because you have nested keypress handlers. Try this:



$('.Number').keypress(function (event) {
var keycode = event.which;
if (!(event.shiftKey == false && (keycode == 46 || keycode == 8 || keycode == 37 || keycode == 39 || (keycode >= 48 && keycode <= 57)))) {
event.preventDefault();
}
});

[#73720] Friday, December 13, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennie

Total Points: 593
Total Questions: 102
Total Answers: 106

Location: Federated States of Micronesia
Member since Fri, Sep 16, 2022
2 Years ago
jennie questions
;