Jump to content

form validation


robertvan

Recommended Posts

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

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

Archived

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

×
×
  • Create New...

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.