Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    16
    Member #
    14937
    Hi all, I have a contact for that requires validating for a number of things. It validates Required for all parts of the form however fine.

    My question is how can I ensure the client fills out the form fully. For instance, here in the UK we use 11 digits for phone numbers, but the form will validate if the clint enters just 1, so how can I ensure the customer actually enters all 11.

    Here is the javascript I am using

    Code:
    function isFilled(str){ return (str != ""); }
        function isEmail(str) {    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); }
        function isDigital(str)    { return(parseFloat(str,10)==(str*1)); }
        function isCurrency(val) {    var re = /^(\$?\d+\$?|\$?\d+\.\d+\$?)$/; return (re.test(val)); }
            function ValidForm(form) {
            var field, i;
            var req = new Array(10);
            var email = new Array(1);
            var digits = new Array(1);
            var currs = new Array(0);
            req[0] = "rw_First_Name";
            req[1] = "rw_Last_Name";
            req[2] = "re_Email";
            req[3] = "rd_Mobile_Number";
            req[4] = "r_Hair_Service";
            req[5] = "r_Stylist";
            req[6] = "r_Preferred_Day";
            req[7] = "r_Preferred_Date";
            req[8] = "r_Month";
            req[9] = "r_Preferred_Time";
            email[0] = "re_Email";
            digits[0] = "rd_Mobile_Number";
    
            for (i=0;i<10;i++)    {
                eval("field = form." + req[i]);
                if (!isFilled(field.value))    {
                    alert("Field '" + field.title + "' is required to be filled in before successful submission.");
                    field.focus();
                    return false;
                    break;
                }}
            for (i=0;i<1;i++)    {
                eval("field = form." + email[i]);
                if (!isEmail(field.value)) {
                    alert("Field '" + field.title + "' is required to be filled in with valid email addresses before successful submission.");
                    field.focus();
                    return false;
                    break;
                }}
            for (i=0;i<1;i++)    {
                eval("field = form." + digits[i]);
                if (!isDigital(field.value)) {
                    alert("Field " + field.title + " is required to be filled in only with digits (0-9) and decimal point before successful submission.");
                    field.focus();
                    return false;
                    break;
                }}
            for (i=0;i<0;i++)    {
                eval("field = form." + currs[i]);
                if (!isCurrency(field.value)) {
                    alert("Field " + field.title + " is required to be filled in only with digits (0-9) a decimal point, or a dollar sign before successful submission.");
                    field.focus();
                    return false;
                    break;
                }}
            return true; }
    www.demontemplates.com
    Cubecart Templates | Cubecart Skins | Cubecart Designs

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Actually, what I have found on most of my clients sites is this is more or a pain than it needs to be.

    I validate phone numbers for numbers only, but since many county phone numbers vary in length as well zip codes. Short of an elaborate script to check the country lengths then verify the actual customer entered values, not much of a way to do it.

    I have found though, that if a potential client doesn't want to provide a phone number ( many only want email communications these days ), they are just going to enter the required number of numbers ( all 1's. Or all 5's ) and keep going.

    If they want to provided a phone number, they will.

    Their are scripts to verify email addresses ( to validate their existence ), again, you will eventually have to trust if they really want you to contact them, they will provide accurate data.

    Then there is the issues with really enforcing all the data to be completely accurate. You'll have potential customers that keep getting validation errors because their info is incomplete, then they just go away, because they think your form is broke.

    The easier you make it for them to contact you the better, then you can eventually get the correct or more accurate data through other forms of communication.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:58 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com