Library code snippets
Field Content Validation
Form Field Validation
Field Content Validation
Ok, I've had several people email me wanting to know how they can validate a field based on a certain criteria. Well, I through this together and hope it will work for you. There are many ways to do this such as Regular Expression, and other functions, but you should be able to implement this rather easily.
function validate_char(field) {
var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
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 Aa-Zz are accepted!");
field.focus();
field.select();
}
}
Now just simply call this like:
<INPUT type="text" name="txt_name" onBlur="validate_char(this)">
Feel free to change the valid variable to anything you'd like to restrict user input.
Related articles
Related discussion
-
Animation Library Javascript - Computer Animation How To
by MarkHewitt (0 replies)
-
Buy cheap Xanax overnight. Cheap Xanax. Overnight delivery of Xanax in US no prescription needed. Cheapest Xanax.
by asleymar (0 replies)
-
Buy Soma online without a prescription. Soma drug no prescription. How to get Soma prescription. Soma cod accepted.
by asleymar (0 replies)
-
Cheap online order Fioricet. Cheap discount Fioricet. Offshore Fioricet online. How to buy Fioricet online without a prescription.
by asleymar (0 replies)
-
Buy Ambien no visa without prescription. Not expensive Ambien prescriptions. Ambien no rx. Cod delivery Ambien.
by asleymar (0 replies)
Related podcasts
-
Raleigh Code Camp reflections, Chrome wins speed tests, GroovyMag
I attended the Raleigh Code Camp last week and had a blast meeting some awesome people (but of course there's never enough time to meet everyone you'd like to!). Some great sessions I attended covered the MS MVC platform and an introduction to MS DLR, both of which I discuss here in a bit more d...
Events coming up
-
Feb
25
Mitcho's talk on Ubiquity and/or JetPack
Cambridge, United States
Our February 2010 JavaScript Meetup will be held on Thursday, February 25th at Microsoft Research Center located at One Memorial Drive in Cambridge. When you arrive security will direct you to the correct floor. There is also parking available at a cheap evening rate in the building. Parking is also free on the street in front of the building at 6 PM.At 6:30 PM our fellow member Mitcho (mitcho.com) will share his knowledge of Ubiquity and/or JetPack. I hear he is an awesome presenter.
When I follow these instructions, I get an "Object expected" error. Any clue why?
This thread is for discussions of Field Content Validation.