Hi, My function; function alfanumeric($ifade) { if(preg_match('/([^\w|\s{0,1}])+/i', $ifade)) return false; else return true; } echo alfanumeric("sample user name"); PHP: I want just words, digits, white spaces. Function is most return false for double or high white spaces. but how ? thanks...
function alfanumeric($ifade) { return preg_match('/^[a-z0-9\s]+$/i', $ifade); } PHP: \w also matches under scores, so if you only want letters, numbers, and spaces, the above should work.
Not sure what you mean. if (alfanumeric('Hello "quote"')) { echo 'Is alfanumeric'; } else { echo 'Is not alfanumeric'; } PHP: Outputs: Is not alfanumeric Which is true.
Thank you this true but I want exaclty that. // I have got this variable $data=" sample user name"; // I want this $data="sample user name"; // I dont want this // white space + white space + white space Code (markup):
I wouldn't bother the user and throw an error for this. I'd just remove the double spaces and continue. $data = preg_replace('/\s{2,}/', ' ', $data); PHP: If you still want to check for double spaces in the function, you can do: function alfanumeric($ifade) { return preg_match('/^[a-z0-9\s]+$/i', $ifade) AND !preg_match('/\s{2,}/', $ifade); } PHP: