Northern Flame Posted April 5, 2008 Share Posted April 5, 2008 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:]]|[~`!@#$%^&*(). =+<>{}|\:;"/?,]|[|]|-)+'; Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 5, 2008 Share Posted April 5, 2008 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.