|
I have created a web form using asp. The form needs the user to input a number and only a number in the input fields. How would be the best way to validate that? I am not good with Javascript so i am open to any and all suggestions.
Thank you
|
|
|
It all depends on whether you want to validate it client-side or server side. Client side saves time etc.
here is some code you could use...
<!--------------------------------------------------------------------
<html>
<title> blank page </title>
<head>
<style type="text/css">
body { font-family:verdana; font-size:8pt; text-decoration:none}
</style>
<script type="text/javascript" language="javascript">
function verifyField(string, daMode) {
if (!string.value) return false;
if(daMode == "digit") var iChars = "0123456789./";
newValue = ""
for (var i = 0; i < string.value.length; i++) {
if (iChars.indexOf(string.value.charAt(i)) != -1)
{
newValue += string.value.charAt(i)
}
}
string.value = newValue
return true;
}
</script>
</head>
<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0">
<form name="form_name">
<table cellpadding=0 cellspacing=5 border=0>
<tr>
<td align="left">Your Number:</td><td align="left"><input type="text" name="dob" onKeyUp="verifyField(this,'digit')"></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr></table>
</form>
</body>
</html>
---------------------------------------------------------------------------->
what it does is it detects a non-digit and removes it.
Hope this helps ;-)
|
|
|
Thank You, I do believe this will help me.
|
|
|
|
|
|
|
|
|
|