in my application i have textbox in that user can't enter digit is there any solution for this thank u
here is a MSDN and CodeProject article on creating a numeric text box
what programming language? in delphi: add a OnKeyPress event add code
if (( Key >= '0') and(Key <= '9')) then Key := #0;
to this event.
there are many ways to tackle your problem
1)you can assign a validator to a textbox and use the numeric only validator.
2)you can fire your own function in textchanged and capture the text either by using a regular expression or by manually checking if the string contains a nubmer or not.
3)You can try this, make a javscript function
function fncInputNumericValuesOnly(x)
{
var txt = document.getElementById(x).value;
if(txt.length > 1)
{
txt = txt.substr(0,1);
if(!((txt >= 'a' && txt <= 'z') || (txt >= 'A' && txt <= 'Z')))
event.returnValue = false;
}
}
and in the markup of your aspx page have the textbox refer to the function like this
<asp:TextBox id="txtQty" runat="server" onkeypress= "fncInputNumericValuesOnly(this.id)"/>
Hope this helps.
========UPDATED code to make it accept first letter as character and rest as alphanumeric=======
Since you want to enforce only alphabets in first character so you need to check only for the first character, as you are allowing alphanumerics on all other positions then you don't need to check them. (it will allow symbols too in alphanumerics).
i believe you are doing this for passwords check, it will be much neater if you assign a regular expression validator, which causes a regular expression validation to occur when the password box loses it's focus.
Add a RegularExpressionValidator to the page. Set the ControlToValidate to the ID of the TextBox. And use a ValidationExpression of "[^0-9]." or "[a-zA-Z][a-zA-Z0-9]". The first disallows a digit as the first character, but accepts inputs like "%%". The second one requires an initial letter and then zero or more letters (upper and lowercase) and/or digits.