KaLv1n K
KaLv1n K

Reputation: 131

Mysql REGEXP for username

what is Mysql query REGEXP to call this?

@text
@user_name
@4ll_r1ght
@last2
@_last1
@and1more_

Upvotes: 1

Views: 1238

Answers (2)

piotrm
piotrm

Reputation: 12356

SELECT * FROM users WHERE username REGEXP '^\@[0-9a-zA-Z_]+$'

Will select users with usernames starting with @ and consisting of only alphanumeric characters (at least one).

Upvotes: 2

user319198
user319198

Reputation:

I hope you are looking for regular expression for username with specified characters.

Try below :

^[a-zA-Z0-9._-]+@  

This part of the expression validates the ‘username’ section of the email address. The hat sign (^) at the beginning of the expression represents the start of the string.

If we didn’t include sign (^), then someone could key in anything they wanted before the email address and it would still validate.

Here, we are allowing the letters a-z, A-Z, the numbers 0-9, and the symbols underscore (_), period (.), and dash (-). You can add/remove them according to your needs.

Upvotes: 1

Related Questions