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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.