Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Created November 3, 2009 20:37
Show Gist options
  • Save jamsesso/225403 to your computer and use it in GitHub Desktop.
Save jamsesso/225403 to your computer and use it in GitHub Desktop.
function valid($setting, $string) {
if($setting == "email") {
if(preg_match("/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/", $string)) {
return true;
} else {
return false;
}
} elseif($setting == "website") {
if(preg_match("/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/", $string)) {
return true;
} else {
return false;
}
} elseif($setting == "username") {
if(preg_match("/^[a-z0-9_-]{3,16}$/", $string)) {
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment