Script Categories













Forms >>> Validation Num Or Char.

Validates an input field to make sure that only a number or character is entered. If you enter a number or a letter everything you can continue on. But, try entering another value like an exclamation point (!), an ampersand (&), or a dollar sign ($) and see what happens. It even highlights the incorrect entry field for you.


Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function validate(field) {
var valid = "abcdefghijklmnopqrstuvwxyz0123456789";
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry!  Only characters and numbers are accepted!");
field.focus();
field.select();
   }
}
//  End -->
</script>
<form onSubmit="http://yourwebsiteaddresshere.com/script.cgi">
<input
type=text name="entry" onBlur="validate(this)">
<br>
<input type=submit value="Submit Form">
</form>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).




©