feesu
asked on
ASP.NET 2005 - How can I force the user to enter only numbers into a text box?
Hi,
I want to have two text boxes, one is for passport number, and has to accept only numbers (no symbols, or dots or alphanumeric)
And the other one is for the name, accepts only Alphabets (no numbers, symbols etc...)
I want to implement this on key press! Any ready functions?
I want to have two text boxes, one is for passport number, and has to accept only numbers (no symbols, or dots or alphanumeric)
And the other one is for the name, accepts only Alphabets (no numbers, symbols etc...)
I want to implement this on key press! Any ready functions?
In the TextBoxes , there is property for SkinID. Set it as per your needs.
in javascript, there are many things you can do... like the following:
If(IsNaN(document.getEleme ntById("te xtbox").va lue)=true)
{
alert("Please enter only numbers for the passport!");
document.getElementById("t extbox").v alue=docum ent.getEle mentById(" textbox"). value.subs tring(0,do cument.get ElementByI d("textbox ").value.l ength-1)
}
this will alert not to use letters, and remove the invalid character, onKeyUp...
but if someone holds the key down, you're screwed... so the best way would be to loop through all characters in the textbox, and if one is not a number, remove it, and alert the user if any non numerical numbers were found, and with this function type (loop), you can also check for any @non-wanted@ characters... like a dot, !, etc...
If(IsNaN(document.getEleme
{
alert("Please enter only numbers for the passport!");
document.getElementById("t
}
this will alert not to use letters, and remove the invalid character, onKeyUp...
but if someone holds the key down, you're screwed... so the best way would be to loop through all characters in the textbox, and if one is not a number, remove it, and alert the user if any non numerical numbers were found, and with this function type (loop), you can also check for any @non-wanted@ characters... like a dot, !, etc...
If(IsNaN(document.getEleme ntById("te xtbox").va lue)==true )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you use ajax, you can use the Masked Edit Text box:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx