Jump to content


Photo

Form Validation


  • Please log in to reply
5 replies to this topic

#1 Bavilo

Bavilo
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 12 March 2006 - 06:09 AM

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

#2 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 12 March 2006 - 06:20 AM

<?php
if (!is_numeric($_POST['field']){
    echo "Not a number!";
}
else{
    echo "Number!";
}
?>


#3 Bavilo

Bavilo
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 12 March 2006 - 06:27 AM

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

Thanks i will try that in a bit

#4 Bavilo

Bavilo
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 12 March 2006 - 06:51 AM

Schweeeet it works great. Thanks!

#5 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 12 March 2006 - 08:12 AM

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

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

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#6 greycap

greycap
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 12 March 2006 - 09:51 AM

[!--quoteo(post=354126:date=Mar 12 2006, 02:12 AM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 12 2006, 02:12 AM) View Post[/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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users