![]() |
Form Field Check
I have a form written in PHP & one of the fields is the last name. I have some javascript that checks & throws a message that says "ATTENTION: Please enter a last name" if the user forgets to enter a last name/leave that field blank. Is there a way I can use javascript to just throw a message that says you must remove the - or ' from this field before continuing. For instance, at this time, in the last name field, if a user does not enter a last name & th esubmit button is pressed, a box pops up saying "Please enter a last name". If there anyway to edit the last name field java code so if the user last a trailing space or a - or a . it will throw a message telling them only letters are allowed in this field? Here is my code. I greatly appreciate your help.
Code:
<html |
Quote:
Form validation of the pattern if(document.forms[0].lname.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe. Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum. Forms names are obsolete - use an id rather than a name. Likewise docuemnt.forms[0] is considered undesirable. To permit only letters, hyphens, apostrophes in a field: Code:
var lstn = document.forms[0].lname.value;See anything wrong here? Code:
if(document.forms[0].location.value == "") { All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit. |
Don't forget that the JavaScript validation is simply for your visitor's convenience so that if they have JavaScript enabled that they get immediate feedback on errors rather than being told about them all after they submit the form. Some visitors (including all those trying to bypass your security on the form) will not have JavaScript available and so you will need to repeat all the validations on the server so as to ensure that the data is actually valid before you use it.
|
| All times are GMT +1. The time now is 08:14 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.