Amen
Amen

Reputation: 713

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.InputField("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?

Upvotes: 0

Views: 259

Answers (1)

josh.trow
josh.trow

Reputation: 4901

In a prototype/pseudocode way:

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

Upvotes: 1

Related Questions