limit password 4 digits

loloscott78 29 Oct, 2010
Hi,

In the form how it 's possible to limit the password field to 4 digits minimum and 9 maximum.
<div class="form_item">
  <div class="form_element cf_password">
    <label class="cf_label" style="width: 300px;">Mot de passe (4 caractères minimum)* </label>
    <input class="cf_inputbox required" maxlength="20" size="4" title="Mot de passe est manquant" id="text_21" name="text_21" type="password" />
    
  </div>
  <div class="cfclear"></div>
</div>

Thank's a lot
GreyHead 29 Oct, 2010
Hi loloscott78,

You can do it with server-side validation; or with a LiveValidation custom validation. I think that there may be an example like that in the forums here somewhere.

Bob
loloscott78 01 Nov, 2010
Hi Bob,

I saw the method, but no post about the syntax to limit digit (max and mini).
If you got it.
Thank's.
GreyHead 01 Nov, 2010
Hi loloscott78 ,

Try this, check the correct input id is used for your form.
window.addEvent('domready', function() {
  var val_password = new LiveValidation('password');
  val_password.add( Validate.Length, {
    minimum: 4,
    maximum: 9,
    wrongLengthMessage: 'Must be between 4 & 9 characters'
  });
});
More info here

Bob

Later: updated to add missing });
loloscott78 02 Nov, 2010
Hi bob,

Where do you insert it? In the validation tab or in the form?
Thank's
GreyHead 02 Nov, 2010
Hi loloscott78,

It's JavaScript and goes into the Form JavaScript box.

Bob
loloscott78 02 Nov, 2010
Hi Bob,

I tested it but nothing work.

Password in my form
<div class="form_item">
<div class="form_element cf_password">
<label class="cf_label" style="width: 300px;">Mot de passe (4 caractères minimum)* </label>
<input class="cf_inputbox required" maxlength="20" size="4" title="Mot de passe est manquant" id="text_21" name="mdp" type="password" />

</div>
<div class="cfclear"></div>
</div>

I wrote this in the form Form JavaScript:
window.addEvent('domready', function() {
var text_21 = new LiveValidation('text_21');
text_21.add( Validate.Length, {
minimum: 4,
maximum: 9,
wrongLengthMessage: 'Must be between 4 & 9 characters'
});
Thank's
GreyHead 03 Nov, 2010
Hi loloscott78;

Sorry, I missed out some closing brackets:
window.addEvent('domready', function() {
  var val_password = new LiveValidation('password');
  val_password.add( Validate.Length, {
    minimum: 4,
    maximum: 9,
    wrongLengthMessage: 'Must be between 4 & 9 characters'
  });
});
You must also have some other validation set or set "Load Chronoforms CSS/JS Files?" to Yes to make sure that the LiveValidation library is loaded.

Bob
loloscott78 03 Nov, 2010
Hi Bob,

Brackets are ok.
Enable Server Side Validation: yes
Load Chronoforms CSS/JS Files?: yes

But always without validation.Not working!


window.addEvent('domready', function() {
var text_21 = new LiveValidation('text_21');
text_21.add( Validate.Length, {
minimum: 4,
maximum: 9,
wrongLengthMessage: 'Must be between 4 & 9 characters'
});
});
ialex 03 Nov, 2010
Hi, i used bob's code and it works!

this is my form's code:

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Nombre(s)*</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="No debe quedar vacío." id="text_2" name="name" type="text" />
  
  </div>


and this is my javascript validation code:
window.addEvent('domready', function() {
  var name = new LiveValidation('text_2');
  name.add( Validate.Length, {
    minimum: 4,
    maximum: 9,
    wrongLengthMessage: 'Must be between 4 & 9 characters'
  });
});


are you sure "text_21" is your textbox id?
GreyHead 03 Nov, 2010
Hi loloscott78,

Sounds as though there may be a JavaScript problem. I tested it and it worked form me and for iAleX.

Please post a link to the form so we can take a quick look.

Bob
GreyHead 04 Nov, 2010
Hi loloscott78,

Fixed - for some reason the missing brackets }); were still missing.

Bob
This topic is locked and no more replies can be posted.