Solved

ignore case in javascript

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now