Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Make sure username contains only: A-Z, a-z, ., _, -, 0-9 (no comma) PHP [closed]
- if(preg_match("/[^w-.?]/", $user)){
- // invalid character
- }
- if(!filter_var($email, FILTER_VALIDATE_EMAIL) || strstr($email,'@yahoo.com')) {
- // either invalid email, or it contains in @yahoo.com
- }
- <?php
- // The validator class
- class Validator
- {
- public function isValidUsername($username)
- {
- if(preg_match('/^[a-zA-Z0-9_-.]+$/', $username)) {
- return true;
- }
- return false;
- }
- public function isYahooMail($mail) {
- if(preg_match('/^[a-zA-Z0-9_-.]+@yahoo.com$/', $mail)) {
- return true;
- }
- return false;
- }
- }
- // The way to use this class
- $username = "otporan_123";
- $email = "otporan@gmail.com";
- $badUsername = "otporan*bad";
- $yahooEmail = "otporan@yahoo.com";
- $validator = new Validator();
- var_export($validator->isValidUsername($username));
- echo "<br />";
- var_export($validator->isValidUsername($badUsername));
- echo "<br />";
- var_export($validator->isYahooMail($email));
- echo "<br />";
- var_export($validator->isYahooMail($yahooEmail));
- echo "<br />";
- ?>
- if(preg_match("/[^-A-Za-z0-9._ ]/", $userName)){
- // there are one or more of the forbidden characters (the set of which is unknown)
- }
- if (!preg_match('/w-/', $username) {
- //throw error
- }
Add Comment
Please, Sign In to add comment