Bavilo Posted March 12, 2006 Share Posted March 12, 2006 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 Link to comment https://forums.phpfreaks.com/topic/4735-form-validation/ Share on other sites More sharing options...
Prismatic Posted March 12, 2006 Share Posted March 12, 2006 [code]<?phpif (!is_numeric($_POST['field']){ echo "Not a number!";}else{ echo "Number!";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/4735-form-validation/#findComment-16585 Share on other sites More sharing options...
Bavilo Posted March 12, 2006 Author Share Posted March 12, 2006 [!--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]<?phpif (!is_numeric($_POST['field']){ echo "Not a number!";}else{ echo "Number!";}?>[/code][/quote]Thanks i will try that in a bit Link to comment https://forums.phpfreaks.com/topic/4735-form-validation/#findComment-16586 Share on other sites More sharing options...
Bavilo Posted March 12, 2006 Author Share Posted March 12, 2006 Schweeeet it works great. Thanks! Link to comment https://forums.phpfreaks.com/topic/4735-form-validation/#findComment-16595 Share on other sites More sharing options...
keeB Posted March 12, 2006 Share Posted March 12, 2006 [!--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.. Link to comment https://forums.phpfreaks.com/topic/4735-form-validation/#findComment-16613 Share on other sites More sharing options...
greycap Posted March 12, 2006 Share Posted March 12, 2006 [!--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. Link to comment https://forums.phpfreaks.com/topic/4735-form-validation/#findComment-16621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.