Solved

var must contain

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
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…

732 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