robertvan Posted April 4, 2007 Share Posted April 4, 2007 I have a script that validates blank fields, and improper entrys. I want to validate a couple of the fields (middle_initial,fax_number)for improper data, however it would be ok for them to leave it blank. Thanks Link to comment https://forums.phpfreaks.com/topic/45548-form-validation/ Share on other sites More sharing options...
trq Posted April 4, 2007 Share Posted April 4, 2007 And your question is? Link to comment https://forums.phpfreaks.com/topic/45548-form-validation/#findComment-221104 Share on other sites More sharing options...
jitesh Posted April 4, 2007 Share Posted April 4, 2007 I do not get you. Link to comment https://forums.phpfreaks.com/topic/45548-form-validation/#findComment-221107 Share on other sites More sharing options...
robertvan Posted April 4, 2007 Author Share Posted April 4, 2007 Sorry about the confusion, I want to write a script that will alow blank fields, but not alow improper data. On the form I will ask for a fax number. If they leave it blank that will be okay and will still process. If they were to type in something like fdgfdg into the fax feild it would produce an error message. I will also ask for there name on the form, and I want to check for both blank and improper data, so if they do not type there name into the form or they type 44444 into the form for the name entry it will show an error message. My question is " HOW DO I DO THIS". Thank You Link to comment https://forums.phpfreaks.com/topic/45548-form-validation/#findComment-221235 Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 This may give you idea <script language=javascript> fucntion check(){ if((trim(document.formname.fax.value) != "") and !isnumber(document.formname.fax.value)){ alert('Invalid fax no'); return false; } } function trim() { if (this.length > 0) { var retstr = this.replace(/^\s+/,""); retstr = retstr.replace(/\s+$/,""); return retstr; } else return this; } function isnumber(val){ var realNoRegEx = /^([0123456789]+$/i; if (!realNoRegEx.test(val)) return false; return true; } </script> Link to comment https://forums.phpfreaks.com/topic/45548-form-validation/#findComment-221807 Share on other sites More sharing options...
Fergusfer Posted April 5, 2007 Share Posted April 5, 2007 Here's an idea for PHP: <?php // $input is a string representing some form input you want to validate if ($input != '') { // validation } // use $input as you see fit ?> Link to comment https://forums.phpfreaks.com/topic/45548-form-validation/#findComment-221816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.