Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


ignore case in javascript

Posted on 2007-03-29
Medium Priority
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
Question by:ams7503
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Assisted Solution

by:Yury Merezhkov
Yury Merezhkov earned 75 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) {
} else {
LVL 15

Accepted Solution

stanscott2 earned 75 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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

730 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