Solved

var must contain

Posted on 2000-03-24
3
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
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…
Six Sigma Control Plans

717 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