开发者

How do I write a method to validate if the username created is too short?

I have the following html code:

<div class="result hide" id="userNameTooShort"><span class="error">Your username needs to be six characters long.</span></div>

I want this to display when a user types less than 6 characters in the username input field. The hide class displays none if it is valid.

Here is the input field I created in javascript:

createFieldObjects: function(){
    unField = new forms.Inpu开发者_StackOverflowtField("tUserName", /^(?=.*[a-zA-Z\d])(\w|[\.\@\-\?\,\&\''\/\_\""]){6,}$/);
},

How do I write the javascript to display the error message when the user types less than 6 characters?


In a prototype/pseudocode way:

if $('tUserName').value.length < 6
  (set the div to display)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜