Jump to content

ereg() help


Northern Flame

Recommended Posts

i found a string that you can place into the ereg function

and used it for my usernames when a user registers to my

site, the string works fine except it doesnt allow my users

to enter numbers in their username, im not too good with

understanding these kinds of patters so can someone help

me edit this string so that i can accept numbers too?

 

i know it has something to do with the "digit" but i dont

know if i have to take out digit, :digit:, [:digit:], or [[:digit:]]

and i dont want to mess up the string so can someone help

me?

 

heres me string:

 

$pattern = '([[:digit:]]|[~`!@#$%^&*(). =+<>{}|\:;"/?,]|[|]|-)+';

Link to comment
https://forums.phpfreaks.com/topic/99714-ereg-help/
Share on other sites

personally i use preg_match,

 

if you want to verify if a string is only numbers/letters then you could use:

 

preg_match("/\A[a-zA-Z0-9]{6,16}$/i",$string);

 

this would return 1 if the string is only letters/numbers and is between 6-16 characters long.

--------

preg_match("/\A[a-zA-Z0-9\.]{6,16}$/i",$string);

same as above but also allows . (periods)

------------

preg_match("/\A[a-zA-Z0-9\._-]{6,16}$/i",$string);

same as above but allows periods, dashes and underscores.

------------

preg_match("/\A[a-zA-Z0-9\._ -]{6,16}$/i",$string);

same as above but allows periods, dashes and underscores and spaces.

------------

preg_match("/\A[a-zA-Z0-9_-]{6,16}$/i",$string);

same as above but allows dashes and underscores.

-----------

 

 

If the string does not match it will return 0.

 

 

 

hope this helps,

Link to comment
https://forums.phpfreaks.com/topic/99714-ereg-help/#findComment-510121
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.