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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validation on a field for a "last name" while allowing for an Apostrophe

    Hi guys,

    I am trying to re-work some pre-written Javascript code at which I am a novice at (I'm more CSS, HTML, PHP...). I am trying to validate a form field for a Purchaser's last name while accounting for an apostrophe if they have one in their last name.

    I bet it's something simple, but I still haven't been able to figure it out, or write it correctly:


    Code:
    function checkPurchaserName()
    {
      var err = false;
      var f = $(getApogeeElement('purchaser_name_first'));
      var l = $(getApogeeElement('purchaser_name_last'));
    
      if ( f && l &&
           ( f.value.toLowerCase() != first.toLowerCase() ||
             l.value.toLowerCase() != last.toLowerCase() ) )
      {
        error_list[error_list.length] = 'The name of the purchaser must match the applicant.';
        errorHighlight(f);
        err = true;
      }
    
      return err;
    }
    As an example. I started the purchasing process with the name "Patrick O'Malley".

    At the end page where this validation occurs, they have (2) text boxes, one for "first name" and one for "last name". They must type the same exact name for purchaser that they did for applicant, so "Patrick", then "O'Malley"

    Can someone please put me on the right track?

    Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    The code you posted simply requires that the purchaser name must match the applicant name (what is the point of that?) whatever that name is.

    Are you sure that somewhere along the line the apostrophes are not being filtered out? (a-z only) Some names have hyphens as well. Patrick O'Malley-Jones.


    "When the questions are being asked, that's when you come up with the answers." Prospective MP

  • #3
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The point of matching the typed in Purchasing Name to the Applicant name is that we're following state guidelines for a product that we're selling. Can't really get into that right now.

    I have PHP for the initial part of the application that allows for apostrophes and hyphens, and if the last name has an apostrophe or hyphen in it, that it doesn't make the second part of the last name lowercase:

    Code:
    $temp = strtolower("<#policyholder.last_name#>");
        $temp = join("'", array_map('ucwords', explode("'", $temp)));
        $temp = join("-", array_map('ucwords', explode("-", $temp)));
        $result = $temp;
    It looks like that javascript validation that I inserted previously is now converting everything to lowercase, and doesn't allow for special characters. Something I am trying to get help on.

    I forgot to mention that the javascript validation allows the hyphenated last name to go through to purchase completion, but when I have a last name with an apostrophe, it gives me the error message, saying the purchaser name does not match the applicant. That's why I'm stumped.
    Last edited by vitugja; 05-04-2010 at 04:12 PM. Reason: forgot pertinent information

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    I don't do php, but the Javascript method toLowerCase() has no effect on hyphens or apostrophes.

    Code:
    var n = "Patrick O'Malley-Jones";
    n = n.toLowerCase();
    alert (n);
    Try escaping the ' with a backslash \'.
    Code:
    n = n.replace(/'/,"\'");

  • #5
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess this is where I'm confused. I tried something like this earlier, but I believe I'm just putting this in the wrong spot. Where would I put:
    Code:
    n = n.replace(/'/,"\'");
    in this:

    Code:
    function checkPurchaserName()
    {
      var err = false;
      var f = $(getApogeeElement('purchaser_name_first'));
      var l = $(getApogeeElement('purchaser_name_last'));
    
      if ( f && l &&
           ( f.value.toLowerCase() != first.toLowerCase() ||
             l.value.toLowerCase() != last.toLowerCase() ))
      {
        error_list[error_list.length] = 'The name of the purchaser must match the applicant.';
        errorHighlight(f);
        err = true;
      }
    
      return err;
    }
    Thanks for your help. Very much appreciated.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    var f = $(getApogeeElement('purchaser_name_first'));
    f = f.replace(/'/,"\'");
    var l = $(getApogeeElement('purchaser_name_last'));
    l = l.replace(/'/,"\'");
    For what it is worth, it is not a good idea to use the unadorned letter l as a variable as it is too easily confused with the number 1. Likewise O and 0.

    Why are you converting the names to lower case anyway? You said They must type the same exact name for purchaser that they did for applicant, so "Patrick", then "O'Malley", not "patrick" and "o'mALLey".
    Last edited by Philip M; 05-04-2010 at 04:33 PM.

  • #7
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. That's what I tried earlier, and it erased the whole last name and left this on the screen:
    Code:
    /'/
    I'm thinking I need to append it to something else in the code.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by vitugja View Post
    Thanks. That's what I tried earlier, and it erased the whole last name and left this on the screen:
    Code:
    /'/
    I'm thinking I need to append it to something else in the code.
    I think you would do best to post this in the php forum. What you say makes no sense to me.

  • #9
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey sorry, didn't see the last part of your message. The conversion with the toLowerCase() function was there previously without me. I'm trying to just pick apart the code and re-write it without breaking anything. If you have a better suggestion with better validation, I'm all "ears". I am really a beginner, so I'm sorry if it seems like I have to be babied a bit about the code.

    To give a little more info, without giving too much away. The "purchaser name" is basically an online signature. They are buying a policy online. So that's why the applicant name, and the purchaser name have to match. So that someone else can't be buying the policy for someone else. It also matches their credit card name.

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Validation of first and last names (basically a-z hyphen apostophe space) has been covered many times in this forum.

    But I still do not understand why you are having this trouble of apostrophes being deleted. Is there some prior validation of the "applicant name" which is deleting anything but a-z and hyphen?

  • #11
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I know it's been covered a million times in this forum. Trust me I was looking at all the posts for about a whole day before I decided to post my own code today to see if it was some little piece of syntax that was preventing my code from working. I definitely wasn't going to post something up here without giving it an honest effort.


    You're help was appreciated, but I don't think I can ask for much anymore without other coders being able to see all the modules I'm working with because it seems to be much more than that little piece of JavaScript I posted earlier..... Back to troubleshooting.


  •  

    Tags for this Thread

    Posting Permissions

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