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
Solved

var must contain

Posted on 2000-03-24
3
174 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

765 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