Mail and username REGEX for validating in PHP

I have to validate some shit’s in PHP so i did some research and found 2 uber cool snippets to do that:

Mail Validating

if(!preg_match(‘/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/’, $mail))
die(‘Invalid email proved, the email must be in valid email format (such as name@domain.tld).’);

User Validating

if(!preg_match(‘/^[a-zA-Z0-9_.]{3,16}$/’, $mail])) {
die(‘Invalid username proved, the username must be valid to proceed only “a-z, A-Z, 0-9, _, and .” allowed.’);
}

It will allow the user to imput: a-z, A-Z, 0-9, _, and .

Why PHP when you got tons of JS that can do that you my ask ?
Because i don’t trust anyone

2 Comments

  1. PS: luzării ce validează doar în JS și “uită” de serverside o să își ia o mumu epică.

Leave a Reply

Your email address will not be published. Required fields are marked *