Results 1 to 4 of 4

Thread: Javascript comparison operator but IGNORE case-sensitivity?

  1. #1
    Join Date
    Jan 2009
    Posts
    82
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Javascript comparison operator but IGNORE case-sensitivity?

    I'm comparing two textfields with something like

    if (document.form1.code.value != "FRNretrt83473")

    Can the comparison be fixed to ignore case sensitivity.

    Thanks.

  2. #2
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    have you tried the toLowercase() method?

  3. #3
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    I agree with you thenajsays this is the right function to use.

    I would change the function like this for clarity.

    var fieldvalue= document.form1.code.value.toLowerCase();
    if (fieldvalue != "frnretrt83473") {

  4. #4
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by monaya View Post
    I'm comparing two textfields with something like

    if (document.form1.code.value != "FRNretrt83473")

    Can the comparison be fixed to ignore case sensitivity.

    Thanks.
    Code:
    String.prototype.equalTo = function( str )
    {
      return this.toLowerCase() === str.toLowerCase();
    }
    
    
    if( document.form1.code.value.equalTo( "FRNretrt83473" ) )
     ...

Bookmarks

Posting Permissions

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