Solved

ignore case in javascript

Posted on 2007-03-29
2
1,004 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wrapper for APPs 9 76
insert text field data into html script 13 41
Else condition 9 16
Adding Row and Cell on a table 14 17
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

776 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