How Can I make it possible that my Text box will take only numbers and ,(coma) and spaace and + characters using Jquery?
I am very bad at client side scripting. I am trying to use JQuery If possible. I have aspx page that has a web form with id = "formUI". This form contains multiple asp text boxes. One of them is (id=)txtPhone. This text-box will take one or more phone开发者_如何学Python numbers separated by comma.I have link of jqury1.6.1.js and jqueryvalidator plugging in my aspx page. How can I validate this Text field using jquery? I am looking forward for an easy and concrete solution from the talented coders of the community of stake overflow.
You could do:
$('#txtPhone').keydown(function(event) {
if(!$(this).val().test(/^[\d,\s+]*$/g))
event.preventDefault();
});
Hope this helps. Cheers
Check this. This is a code on making textbox to accept only numbers. You can easily extend it to choose your needs. Also check this :How to allow only numeric (0-9) in html inputbox using jQuery?
of course create this function:
function fncInputNumericValuesOnly()
{
if(!(event.keyCode==45||event.keyCode==46||event.keyCode==48||event.keyCode==49||event.keyCode==50||event.keyCode==51||event.keyCode==52||event.keyCode==53||event.keyCode==54||event.keyCode==55||event.keyCode==56||event.keyCode==57))
{
event.returnValue=false;
}
}
and call it with:
onkeypress= "fncInputNumericValuesOnly('txtQty')"
精彩评论