Forms field format

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

lola2001

Thread Starter
Joined
Jan 29, 2001
Messages
1,972
Is there a way to make a form field that will verify that the correct information is typed in. For instance I have a form field that asks for a phone number, including the area code and also a field that asks for an email address. I want to make sure that the correct format is typed in and if nothing is typed in those fields then the page should be refreshed with a message saying they missed a field. Am I making any sense here? Thanks.

I'm using Dreamweaver.
 
Joined
Jul 29, 2001
Messages
21,334
You need to write a java function to validate the form elements and that will fire when the form is dubmitting using the forms onSubmit event. Here's a simple one for an email address

PHP:
function ValidateForm(formname)
if(form.Email.value == "")
	{ 
		alert('You must type in an Email address') 
		formname.Email.focus();
		return false;
} 
else if(form.Email.value.indexOf('@')== -1)
	{
		alert('Your Email address is missing an @ symbol') 
		formname.Email.focus();
		return false;
	//if the EmailAddrs does not contain a full stop
	}
else if(form.Email.value.indexOf('.')== -1)
	{
		alert('Your Email address is missing a period') 
		formname.Email.focus();
		return false;
	}
 

lola2001

Thread Starter
Joined
Jan 29, 2001
Messages
1,972
Ok, thanks. I'll use that. Shouldn't there be something in Dreamweaver that would make it easier though?
 
Joined
Jul 8, 2002
Messages
14,681
If you have a language that supports Regular Expressions, that could give you much better validation.
 
Joined
Jul 8, 2002
Messages
14,681
If your server has PHP, heres how you can validate a phone number (I just made this real quick, and im bad at regexps, so its probably not perfect. It doesn't like international numbers, or people that put their area code in parenthesis).

PHP:
if(ereg("^([2-9]{3})(-?)([0-9]{3})(-?)([0-9]{4})$", $phone))
{echo("$phone is a valid phone number");}
else {"$phone is not a valid phone number");}
It will validate a number that
-Starts with 3 digits, 2-9
-Optionally a - between area code + first 3 digits of number
-3 Digits 0-9
-Optionally a - between first 3 digits and last 4 digits of number
-4 digits, 0-9
 

lola2001

Thread Starter
Joined
Jan 29, 2001
Messages
1,972
Thanks brendan but you didn't have to go to all that work. I don't know a thing about PHP other then yes, the server does support it. I've been trying to learn a bit about it on the internet but I can't really find anything for beginners who know NOTHING. Oh well. I will keep this info though for the future. Thanks.
 
Joined
Jul 8, 2002
Messages
14,681
May I ask what you are using to process the form?
If your using another language (Perl, ASP, whatever), I'm sure you can validate a phone number in that language.
If your just using a mailto: command or something, I HIGHLY reccommend you switch to PHP. Its much more powerful & reliable. You don't even need to learn the language to process a form, there are ready-made scripts for this.
 

lola2001

Thread Starter
Joined
Jan 29, 2001
Messages
1,972
I'm just using HTML. I'm just using "insert form" in dreamweaver, then using FormMail from the server. It's just a small little form with a few fields but the client whats to make sure the use puts in an actual phone number and email address. I will switch to PHP when I figure it out. Thanks for the help.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top