javascript - How Can I Validate User Name using Regex - Stack Overflow

I want to validate the user_name field using REGEX with a Javascript functionI want the following requ

I want to validate the user_name field using REGEX with a Javascript function I want the following requirement for a user_name to be filled in

  • user_name must start with a letter
  • user_name can contains only letters, numbers, underscore and period (.)
  • user_name can not contain white spaces
  • user_name can not be longer than 25 characters

How Can I make a REGEX Expression under the above mention requirements.

I want to validate the user_name field using REGEX with a Javascript function I want the following requirement for a user_name to be filled in

  • user_name must start with a letter
  • user_name can contains only letters, numbers, underscore and period (.)
  • user_name can not contain white spaces
  • user_name can not be longer than 25 characters

How Can I make a REGEX Expression under the above mention requirements.

Share edited Mar 20, 2013 at 13:38 Xophmeister 9,2295 gold badges50 silver badges98 bronze badges asked Mar 20, 2013 at 13:35 Sitara ShaheenSitara Shaheen 593 silver badges5 bronze badges 4
  • 2 Make sure you are also validating the user name on the server side -- client side validation (via javascript) can never be relied on. If the client has javascript disabled, you'd better be checking things on the server! – Chris Baker Commented Mar 20, 2013 at 13:40
  • You should have a bash yourself,first. Here's a great site. – user1945782 Commented Mar 20, 2013 at 13:40
  • In addition to the resource Westie mentioned, here's another useful tool: gskinner./RegExr – Chris Baker Commented Mar 20, 2013 at 13:41
  • 3 What is the problem? Designing the regular expression? Implementing that regular expression in JavaScript? There are plenty of tutorials on JS and regular expressions that you can find via search engines, presumably you have tried them before asking people to investigate your problem personally. What code have you produced so far? – Quentin Commented Mar 20, 2013 at 13:41
Add a ment  | 

3 Answers 3

Reset to default 4

you can try:

   /^[a-z][a-z0-9_\.]{0,24}$/i

Try this regexp:

/^[a-z][\w\.]{0,24}$/i
  • \w matches [a-z0-9_]
  • The /i flag makes the match case-insensitive

Please don't miss reading this ment.

Use [A-z] for the first character. It covers upper and lower case letters.

And you can use [A-z0-9_.]{24} for the other 24 characters.

/[A-z][A-z0-9_\.]{24}/ should do it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744880595a4598816.html

相关推荐

  • javascript - How Can I Validate User Name using Regex - Stack Overflow

    I want to validate the user_name field using REGEX with a Javascript functionI want the following requ

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信