How to determinate if a value is digital

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I want to determinate if a value in a Text is digital or character.
How can I determinate it with Javascript
 
You can use a regular expression for this. If you use the
RegularExpressionValidator control it will check it client side and server
side for you. If like me you find regular expresions somethign of a dark art
there is a good library of the here http://www.regexlib.com/
 
In javascript, You can use KeyPress Event also to find out the Char or digital.

For Example, (The following example will allow 0-9, a-z, A-Z, Underscore and
Dots in the UserName Text box in ASP.Net)

Place the following line in the Form_Load Function.

txtUserName.Attributes("onKeyPress") = "return chkUserNameKeyPress(event,'"
& txtUserName.ClientID & "')"

Place the following code in the Design form.

<script language=javascript>
function chkUserNameKeyPress(e,Id)
{
if(48 <= e.keyCode && 57 >= e.keyCode)
return true;
else if(97 <= e.keyCode && 122 >= e.keyCode)
return true;
else if(65 <= e.keyCode && 90 >= e.keyCode)
return true;
else if (e.keyCode == 46 || e.keyCode == 95 || e.keyCode ==
8)
return true;
else
return false;
}

I hope it will helps you.

with regards,
Murali
 
Back
Top