Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript, regular expressions

Status
Not open for further replies.
Jun 5, 2006
28
US
Hi,
I am looking to create a regular expression that only allows Upper Case and Lower Case Letters and hyphens.

I have the following so far which allows for uppercase and lower case characters. How do I modify it to include "-" also?

var re = new RegExp("^([a-zA-Z])+$");
 
j4606, you're close:

Code:
[a-zA-Z[!]\[/!]-]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
This is good to all consideration.
[tt]var re=new RegExp("^([a-zA-Z[highlight]-[/highlight]])+$");[/tt]
This are unnecessary but eventually fine.
[tt]var re=new RegExp("^([a-zA-Z[highlight]\\-[/highlight]])+$");[/tt]
[tt]var re=/^([a-zA-Z[highlight]\-[/highlight]])+$/;[/tt]
This is deficient but works by fortune that "-" has no need to escape.
[tt]var re=new RegExp("^([a-zA-Z[red]\-[/red]])+$");[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top