Solved

var must contain

Posted on 2000-03-24
3
149 Views
Last Modified: 2010-03-05
how do i say that a variable must contain
only the characters a through z or A through Z or 0 to 9

ie legal
Test
test
test1
test2

illegal
test 1
test+1

i tried
 
if(m/a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|0|1|2|3|4|5|6|7|8|9/){  
but it wont work
0
Comment
Question by:boofulls
3 Comments
 
LVL 3

Accepted Solution

by:
bigbed earned 50 total points
ID: 2653135
if(/^[a-zA-Z0-9]*$/)

if you would allow underscore (_), then
use:
if (/^\w*$/)

0
 
LVL 84

Expert Comment

by:ozo
ID: 2654414
#or
if( /[\W_]/ ){ illegal }else{ legal }
0
 

Author Comment

by:boofulls
ID: 2660083
both good but bigbed got there first
sorry ozo :(
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

11 Experts available now in Live!

Get 1:1 Help Now