473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Plz urgent!string.match!

Hi,

I want to validate whether a string is having only alphabets,
numbers, '-' and '_'.

Is there any way to do this like the one in Perl
( /^[0-9][A-Z][_][-]$/) ?

Let me know the earliest?

Jul 23 '05 #1
3 1874
Something like this ?

<script type="text/javascript">
var strSample = 'abd_def-123_-';
var reg = /^(\w|\d|-|_)+$/;
var boolResult = reg.test(strSample);
alert(boolResult);
</script>

oeyvind

--
http://home.online.no/~oeyvtoft/ToftWeb/

"learner" <v_********@yahoo.com> skrev i melding
news:cg********@odak26.prod.google.com...
Hi,

I want to validate whether a string is having only alphabets,
numbers, '-' and '_'.

Is there any way to do this like the one in Perl
( /^[0-9][A-Z][_][-]$/) ?

Let me know the earliest?

Jul 23 '05 #2
"learner" <v_********@yahoo.com> writes:
I want to validate whether a string is having only alphabets,
numbers, '-' and '_'.
Letters and digits are easy, if you only want English language
letters.
Is there any way to do this like the one in Perl
( /^[0-9][A-Z][_][-]$/) ?


That looks like a perfectly good Javascript regular expression, except
that it probably doesn't do what you want.
That regular expression matches only strings on the exact form:
digit letter underscore minus

Try
/^[-0-9A-Z_]+$/g
or the abbreviated form (\d matches digits, \w matches letters or underscore)
/^[-\d\w]$/

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
JRS: In article <cg********@odak26.prod.google.com>, dated Thu, 26 Aug
2004 22:24:08, seen in news:comp.lang.javascript, learner
<v_********@yahoo.com> posted :
I want to validate whether a string is having only alphabets,
numbers, '-' and '_'.

Is there any way to do this like the one in Perl
( /^[0-9][A-Z][_][-]$/) ?

Let me know the earliest?

^ --- please.

That expression does not do what you want, as has been explained.

Rather than testing whether the whole string contains only those
characters with /^[ characters ]*$/ it may be quicker to see if it
contains any character other than those : /[^ characters ]/ .

The latter process should stop at the first alien; the former, depending
on implementation, probably scans the whole string even if it is faulty.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.