...

View Full Version : Form validation



soulfly
09-09-2008, 01:28 PM
Hi all,
I've made a form validation in an inquiry page but there seems to be a problem. I've made this validation from Dreamweaver and it writes all those draggy codes and I don't wanna stick with Dreamweaver with for form validation.

Everything seems to be working fine but there's a mandatory field which doesn't accept a blank input. A pop-up shows when this field is blank on submission. Till here I'm satisfied but when I type a space(s) this damn thing accepts it. And this is what creating a problem.

Any help for me? Moreover, if there's a formvalidation for "email", "numbers" & other special characters then please share with me.

Sorry to bug you and many thanks.

Regards,
SF

Philip M
09-09-2008, 01:55 PM
fieldname = fieldname.replace(/^\s+/,""); // strip leading spaces

if (/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(email.value)) { // email validation

if (/[^0-9]/g.test(fieldname.value)) { // only numbers 0-9



Spotted in a toilet in a London office block: TOILET OUT OF ORDER. PLEASE USE FLOOR BELOW

soulfly
09-09-2008, 02:04 PM
Hi Philip,
Thanks for the reply. Could u plz elaborate more?

Thank you.

Regards,
SF

Philip M
09-09-2008, 02:33 PM
Hi Philip,
Thanks for the reply. Could u plz elaborate more?

Thank you.

Regards,
SF

I am not sure what you mean. These are regular expressions to test for the things you wanted. Obviously you must replace "fieldname" by the actual name of your fields. If it is not clear or you are unable to work it out then you should give up the idea as the topic is too advanced for you. But of course you will need to write the rest of the scripts:-

Example:-


<input type = "text" size = "20" name = "txt1" id = "txt1" onblur = "testNumsOnly(this)">

<script type = "text/javascript">
function testNumsOnly(which) {
fld = which.value;
if (/[^0-9]/g.test(fld)) {
alert ("You may only enter numbers into this field");
which.value = "";
which.focus();
return false;
}
}
</script>



Sign in Budapest Zoo:- Please do not feed the animals. If you have any suitable food, give it to the guard on duty.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum