regex - jQuery allow specific numbers for mobile number -
i want allow enter mobile number these combinations(7 or 8 or 9).
i restricting alphabets(allow numbers) how restrict numbers other 7 or 8 or 9.
$(document).on('keypress', '.mobnum', function (e) { //if letter not digit display error , don't type if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { if (e.which == 118){ return true; }else{ return false; } } });
use following function restict mobile number
$(document).on('keypress', '.mobnum', function (e) { var mobnum="987654321"; if (mobnum === ''|| mobnum === 'null'|| mobnum === null || phonenumber(mobnum)=== false) { } else { operations } }); function phonenumber(mobnum) { var pattern = new regexp(/^[789]\d{9}$/i); return pattern.test(mobnum); };
Comments
Post a Comment