Added method \ncc\Utilities > Validate > nameFriendly()
https://git.n64.cc/nosial/ncc/-/issues/4
This commit is contained in:
parent
46f6cbba70
commit
a3c3322f28
1 changed files with 17 additions and 0 deletions
|
@ -258,4 +258,21 @@
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the input is considered "name friendly" and does not
|
||||||
|
* contain any special characters, spaces or weird prefixes
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function nameFriendly(string $input): bool
|
||||||
|
{
|
||||||
|
if (!preg_match('/^[a-zA-Z0-9_]+$/', $input))
|
||||||
|
return false;
|
||||||
|
if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $input))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue