PDA

View Full Version : [SOLVED] preg math help!



shedokan
March 14th, 2008, 04:14 PM
I want to check if the user has entered chars other than:
A-Z
a-z
0-9
_

is that possible? and how?

by the way I'm using php.

Keith Hedger
March 14th, 2008, 04:37 PM
ctype.h

isalnum Checks whether a character is alphanumeric (A-Z, a-z, 0-9)

isalpha

iscntrl Checks whether a character is a control character or delete ( decimal 0-31 and 127)

isdigit Checks whether a character is a digit (0-9)

isgraph Checks whether a character is a printable character, excluding the space (decimal 32)

islower Checks whether a character is a lower case letter (a-z).

isprint Checks whether a character is printable (decimal 32-126).

ispunct Checks whether a character is punctuation (decimal 32-47, 58-63, 91-96, 123-126)

isspace Checks whether a character is white space - space, CR HT VT NL, FF.

isupper Checks whether a character is an upper case letter (A-Z).

isxdigit Checks whether a character is hex digit (0-9, A-F, a-f)

mssever
March 14th, 2008, 05:18 PM
I want to check if the user has entered chars other than:
A-Z
a-z
0-9
_

is that possible? and how?

You didn't specify the language you're using. The following regular expression would work in many languages:
^[^a-zA-Z0-9]*$ Many languages support shortcuts which would shorten the regexp. But this would work if your language uses regexps.

hod139
March 14th, 2008, 07:49 PM
If C++: http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.3

shedokan
March 15th, 2008, 10:41 AM
Sorry forgot, I'm using php

smartbei
March 15th, 2008, 11:06 AM
This should work for you:


<?php
$pattern = "/^[0-9a-zA-Z]*$/";
$string = "testing213211c";
echo "Number of Results found: ", preg_match($pattern, $string, $matches);
?>

shedokan
March 15th, 2008, 05:16 PM
actually I took what mssever said and did it exacly like you did but thanks anyway.