Validating Common Form Input - Part 2 Validating a username

简介:

用户名一般都是字母组成,包括[0-9],[a-z],可以是大小写。另外字符还有一些字符限制,比如$, #, £等。

一般用户名有一定的长度限制,必须去适应数据库对应栏位长度。

1.用户名必须是小写,且长度不超过16位

 
  1. function validate(form) {  
  2.   // Regular expression for username  
  3.   var rgx = /^[a-z]{0,16}$/;  
  4.   if(!rgx.test(form.elements.username.value))  
  5.     return false;  
  6.   return true;  
  7. }  

2. 前面基础上,用户名至少8个字符,至多16位。且可以是大小写字母

 
  1. function validate(form) {  
  2.   // Regular expression for username  
  3.   var rgx = /^[a-z]{8,16}$/i;  
  4.   if(!rgx.test(form.elements.username.value))  
  5.     return false;  
  6.   return true;  
  7. }  

3.在前面基础上,允许字母和数字

 
  1. function validate(form) {  
  2.   // Regular expression for username  
  3.   var rgx = /^[a-z0-9]{8,16}$/i;  
  4.   if(!rgx.test(form.elements.username.value))  
  5.     return false;  
  6.   return true;  
  7. }  

4.忽略前面和后面的空格

 

 
  1. function validate(form) {  
  2.   // Regular expression for username  
  3.   var rgx = /^\s*[a-z0-9]{8,16}\s*$/i;  
  4.   if(!rgx.test(form.elements.username.value))  
  5.     return false;  
  6.   return true;  
  7. }  

 



本文转自 randy_shandong 51CTO博客,原文链接:http://blog.51cto.com/dba10g/456629,如需转载请自行联系原作者

相关文章
|
Java 应用服务中间件 Linux
SpringBoot - Processing of multipart/form-data request failed. Unexpected EOF read on the socket
SpringBoot - Processing of multipart/form-data request failed. Unexpected EOF read on the socket
1501 0
SpringBoot - Processing of multipart/form-data request failed. Unexpected EOF read on the socket
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
config.guess: unable to guess system type、config.sub: missing argument
config.guess: unable to guess system type、config.sub: missing argument
133 0
|
Java
The type XXX cannot be resolved. It is indirectly referenced from required .class files
The type XXX cannot be resolved. It is indirectly referenced from required .class files
126 0
User Parameter UI2WD_TRKORR_CUST is not maintained
User Parameter UI2WD_TRKORR_CUST is not maintained
110 0
User Parameter UI2WD_TRKORR_CUST is not maintained
Cannot find source code based button in SE24
When you are logging on to customer system for incident handling, you want to switch to source code to perform some keyword search. However, you could not find button “Source code based builder” in toolbar, with following warning message: ———————————————— 版权声明:本文为CSDN博主「汪子熙」的原创文章,遵循CC 4.0 BY-SA版权协
127 0
Cannot find source code based button in SE24
OPA 15 - find existing item by its type.note
Created by Wang, Jerry, last modified on Nov 08, 2015
OPA 15 - find existing item by its type.note