Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Form validation

  1. #1
    New Coder
    Join Date
    Dec 2005
    Location
    Soul city
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form validation

    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
    Soulfly

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Code:
    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

  • #3
    New Coder
    Join Date
    Dec 2005
    Location
    Soul city
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Philip,
    Thanks for the reply. Could u plz elaborate more?

    Thank you.

    Regards,
    SF
    Soulfly

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Quote Originally Posted by soulfly View Post
    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:-

    Code:
    <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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •