Solved

ignore case in javascript

Posted on 2007-03-29
2
1,007 Views
Last Modified: 2008-02-01
is there a way to ignore case in javascript?
I would like to check if the value of the country text box is either UNITED STATES or United States or USA or usa- if,so I would like to change it to US
0
Comment
Question by:ams7503
2 Comments
 
LVL 7

Assisted Solution

by:RealSnaD
RealSnaD earned 25 total points
ID: 18817378
Convert everything to lower case and then compare:

var original = ”usa”;

var input = document.getElementById("Your_Input_Field_Here").value;

var userInput = input.toLowerCase();

if(original == userInput) {
   alert("Match!");
} else {
   alert("Error!");
}
0
 
LVL 15

Accepted Solution

by:
stanscott2 earned 25 total points
ID: 18817395
Use a regular expression for this:

var myVal = "USA";

if (myVal.match(/^(United States|usa)$/i) { alert("Match"); }

The "i" after the regular expression makes the match case insensitive.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question