Javascript form checker, how to ignore case sensitive?

Discussion in 'JavaScript' started by philb, Nov 10, 2010.

  1. #1
    I've got a bit of javascript to to check a field in a form on my web page.

    It's a competition so I need to make sure the visitor types it in correctly.

    the javascript to check the 'answer' field is


     if (form.answer.value != "brabantia") {	
        alert( "oops! try again?" );
        form.answer.focus();	
        return false ;
      }
      return true ;
    }
    Code (markup):

    but this is case sensitive.

    I'd like to add some kind of other check for "Brabantia" too.

    The javascript needs to return true whether the visitor enters 'brabantia' or 'Brabantia'

    Any help?

    Phil
     
    philb, Nov 10, 2010 IP
  2. philb

    philb Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've worked around the problem by adding a command in the form box to turn all uppercase to lowercase.

    This means the javascript check above only receives lowercase and it works fine.

    To strip the uppcase in the formfield I used

    <input name="answer" type="text" id="answer" maxlength="25" onChange="javascript:this.value=this.value.toLowerCase();"/>
    Code (markup):
     
    philb, Nov 10, 2010 IP