MrEnder
03-22-2010, 02:26 AM
how do I check if a user has entered a number?
Like I don't want them to enter a number
so I'm trying to do
else if($firstNameSignUp IS A NUMBER)) {
$firstNameSignUpError = "Your first name cannot be a number you entered " . $firstNameSignUp;
$firstNameSignUp = "";
}
how can I do this?
Nightfire
03-22-2010, 03:09 AM
use is_int
if(is_int($str)){
echo 'number';
}
MrEnder
03-22-2010, 03:15 AM
but then what if the user enters their name as 3.141592654, or s1, or even worse $ ?
im now trying to work with
if(!preg_match("/^[\w-]+$/", $firstNameSignup)) {
$firstNameSignupError = "Your first name cannot contain numbers or symbols, you entered " . $firstNameSignup;
$firstNameSignup = "";
}
but its not working =[
MattF
03-22-2010, 03:58 AM
if (preg_match('#[^a-z]+$#i', $firstNameSignup)) {
MrEnder
03-22-2010, 04:05 AM
if (preg_match('#[^a-z]+$#i', $firstNameSignup)) {
you are slowly becoming my best friend lol thanks!!!
if (preg_match('#[^a-z]+$#i', $firstNameSignup)) {
ok one more question...
what if they could use numbers and letters but not symbols except - and _?
oh ya and for e-mail
how will that work
letters+@+letters+.+2-4letters
MattF
03-22-2010, 04:19 AM
Numbers, letters, underscore and hyphen:
'#^[^\w\-]$#i'
E-mail:
'#^[\w\.\+\-]{1,}@(?:[\w\-]+\.){1,}[a-z]{2,4}$#i'
MrEnder
03-22-2010, 04:21 AM
thank you once again your amazing ^.^
dang the number one is not quite working =[
its allowing symbols other then - and _
MattF
03-22-2010, 04:31 AM
dang the number one is not quite working =[
its allowing symbols other then - and _
It can't be passing anything else. \w only covers underscore, letters and numbers.
http://docs.google.com/viewer?a=v&q=cache:tpOT17RuGWAJ:www.phpguru.org/downloads/PCRE%2520Cheat%2520Sheet/PHP%2520PCRE%2520Cheat%2520Sheet.pdf+pcre+cheatsheet&hl=en&gl=uk&pid=bl&srcid=ADGEESjXFa-n63bgF9jNBPwClHBTijkRqmWgci35rRaHKiDXXk0t1a8vbbx-48FESpaawjbKaSwyNotCO8GC2jnpzxjxV6cR41XouAkRsp5cLRzcwW6jumZp29IUtRZGymSnX4jLY4eJ&sig=AHIEtbTnRemKs0DRynWGf9CE7_1IxdYnpA
MrEnder
03-22-2010, 04:35 AM
It can't be passing anything else. \w only covers underscore, letters and numbers.
http://docs.google.com/viewer?a=v&q=cache:tpOT17RuGWAJ:www.phpguru.org/downloads/PCRE%2520Cheat%2520Sheet/PHP%2520PCRE%2520Cheat%2520Sheet.pdf+pcre+cheatsheet&hl=en&gl=uk&pid=bl&srcid=ADGEESjXFa-n63bgF9jNBPwClHBTijkRqmWgci35rRaHKiDXXk0t1a8vbbx-48FESpaawjbKaSwyNotCO8GC2jnpzxjxV6cR41XouAkRsp5cLRzcwW6jumZp29IUtRZGymSnX4jLY4eJ&sig=AHIEtbTnRemKs0DRynWGf9CE7_1IxdYnpA
Ok I am here typing in my form and it allowes me to type
Bobby@ or Tod&11
when I use
'#^[^\w\-]$#i'
But I can't write
@bobby
MattF
03-22-2010, 04:41 AM
Change it to:
'#[^\w\-]+#i'
MrEnder
03-22-2010, 04:43 AM
Change it to:
'#[^\w\-]+#i'
brilliant thank you ^.^
MrEnder
03-22-2010, 04:57 AM
dang now how do I do this
'#[^\w\-\.\,\!]+#i'
allow letters numbers hyphens periods commas and exclamation marks
nm my regex worked fine lol was something else casuing the error ^.^ (bad variable to check against lol)