Jump to content

Archived

This topic is now archived and is closed to further replies.

Bavilo

Form Validation

Recommended Posts

Hello,

I have a form which submits info and emails it to me. I have a few fields that should only take numerical values, such as the zip code field, and phone number field. Is there anyway i can validate those fields and give an error if anything besides numbers have been entered?

Thanks in advance

Share this post


Link to post
Share on other sites
[code]<?php
if (!is_numeric($_POST['field']){
    echo "Not a number!";
}
else{
    echo "Number!";
}
?>[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=354097:date=Mar 11 2006, 10:20 PM:name=Prismatic)--][div class=\'quotetop\']QUOTE(Prismatic @ Mar 11 2006, 10:20 PM) [snapback]354097[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]<?php
if (!is_numeric($_POST['field']){
    echo "Not a number!";
}
else{
    echo "Number!";
}
?>[/code]
[/quote]

Thanks i will try that in a bit

Share this post


Link to post
Share on other sites
[!--quoteo(post=354107:date=Mar 12 2006, 06:51 AM:name=Bavilo)--][div class=\'quotetop\']QUOTE(Bavilo @ Mar 12 2006, 06:51 AM) [snapback]354107[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Schweeeet it works great. Thanks!
[/quote]

You can also use JScript as a validation tool before submit..

Share this post


Link to post
Share on other sites
[!--quoteo(post=354126:date=Mar 12 2006, 02:12 AM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 12 2006, 02:12 AM) [snapback]354126[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can also use JScript as a validation tool before submit..
[/quote]

Yes. But never rely on client side validation. If youre going to validate it on the client, you should still validate on the server side.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.