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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stupid regex question

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

This is driving me nuts ;)

Basically - I **only** wanna allow a-zA-Z0-9_. and - in the filenames. Failing this, it needs to show an error. The code I came up with is:

Code:
	var regtest = /^[a-zA-Z0-9_\.]+$/;
/*	var the_test = regtest.test("someÉÊÈËéêèëÏÌÎïìîÖÔÒöô foo bar.jpg");*/
	var the_test = regtest.test("somfoo bar.jpg");
			
	alert("the_test is " + the_test);

It doesn't seem to match quite right though

I'm a perl programmer, so maybe I've just got the regex or something not quite right for Javascript? (I know there are some subtle differences)

TIA

Andy
 
Hi

Your code works as expected : both tests return [tt]false[/tt]. ( Note the space in the second file name. If you remove all space characters from the names, the second test will return [tt]true[/tt], but the first keeps returning [tt]false[/tt] because the letters with diacritical marks. )


Feherke.
 
Eugh man - knew it had to be something stupid. Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top