Click to See Complete Forum and Search --> : Validation


ozz
03-19-2003, 07:45 AM
Would anyone like to have a quick look at this code and let me know what i need to do for the following?

validate the form with a pop up error message for blank fields

only numbers accepted for the phone number

an proper email address only for the email bit such as joe@bloggs.com

Thanks....




code:


<html>

<head>

<title>Contact Page</title>
</head>

<body>

<form name="form1" method="POST" action="/mail.cgi">
<p>name<input type="text" name="name" size="20"></p>
<p>address<input type="text" name="address" size="20"></p>
<p>phone&nbsp; <input type="text" name="phone" size="20"></p>
<p>email address<input type="text" name="email" size="20"></p>
<p><input type="submit" value="Submit" name="subbutt"><input type="reset" value="Reset" name="rebutt"></p>
</form>

</body>

</html>

khalidali63
03-19-2003, 08:05 AM
There are tonnes of scripts out on the net,

here is one to do just what you are trying..
http://www.a1javascripts.com/essential_scripts/formvalidation/formvalidation.html

Cheers

Khalid

ozz
03-19-2003, 08:10 AM
I have had a bash at validation and can do the basics, but can't figure out the only numbers bit and valid email bit??

:)

ozz
03-19-2003, 12:44 PM
Have taken the info from the above mentioned url, the form now validates all fields, except the phone field still accepts letters and the email field accepts anything including no @'s etc. Anymore ideas as all the bits i have found on the net are way above my head.

davidcholley
03-19-2003, 02:06 PM
Try this link...

http://www.gatewayorlando.com/content/informationrequest.asp

for an example of form field validation on steriods or that's been irradiated. There's a whole ton of Javascript driving the validation so it might just crap out on some browsers (http://www.aspfaq.com/show.asp?id=2424). I'm in the process of shifting it from client-side to server-side. The pages should be up for at least the next three-four days.
Please remember that its not nice to use code without giving proper credit.

ozz
03-19-2003, 02:23 PM
Thanks for your reply, I don't intend to go live with any web stuff as i am just trying to learn basic JS for fun. I seem to be able to pick it up better from examples rather than brainstorming through books. The linked validation is excellent but still way over my head, I am hoping to start with something basic but thanks anyway...

davidcholley
03-19-2003, 03:34 PM
The overall design is based on the idea of using individual functions to handle each individual field. The function that validates the entire form simply calls one function after another.