I need in a mask type field a required length

I need in a MASK type field a required length of 11 characters. I am working with Public Forms, I don't know what function I should add to it. Thanks a lot

Hello @belen_costantin,

You need to specify the input mask. For characters, enter 11 & signs to the Mask property like so:
image

Find more information about Mask rules in the documentation here.

Hola!! Eso me funciona de esta manera:

pero igual me deja enviar el formulario por mas que no haya escrito 11 caracteres, yo quiero que no me deje enviar el formulario si el campo no esta completo

Hello @belen_costantin,

We plan to update the functionality of the Masked field to not allow a form to be submitted if the mask is not filled in. But there is no release date yet.

We can offer paid support for switching the task priority, thus the new feature will be released sooner. If you are interested, please send us an email at [email protected].

As a workaround, you can add custom validation to the field to force a user to fill in the mask:

fd.rendered(function () {
    fd.field('MaskedText1').addValidator({
        name: 'Mask validationr',
        error: 'Complete the field',
        validate:function(value){
            //Specify the number of characters that a user must enter
            var maskLength = 11;

            //remove sapces and underscores
            var eneteredValue = value.replace(/[_\s]/g, '');
            
            if(value.length < maskLength){
                return false;
            }
            return true;
        }
    });
});

Thanks a lot!!! I've realized by testing this portion of code that it only works for common fields not for masked fields. In the masked fields nothing of the function is executed, I don't know if it is an internal library problem!

@belen_costantin,

The code should work for the Masked field type. Are you getting any errors in the browser console (F12)? Please share the screenshot.

Hello @mnikitina,

hope you can help me fix my code:

var IBANlength = [20, 16, 21, 24, 22, 18, 20, 24, 27, 22, 28, 27, 20, 20, 18, 15, 28, 24, 29];

fd.validators.push({
name: 'Mask validationr',
error: 'Please complete the IBAN',
validate:function(value){
    var eneteredValue = value.replace(/[_\s]/g, '');
    for(var i=0; i < IBANlength.length; i++){
        if(fd.field('IBAN').value < IBANlength[i]){
            return false;
        }
        return true;
        }
    }
});  

image

The code should check the entered length of the maskedinput (IBAN) and if it is less give an error message.

Hello @Nikita_Kurguzov

hope you can help me with my code.
I would like to see length checked.
That is, if the entry is too short, this error message should be thrown.
However, it does not replace the underscores.

var IBANlength = [20, 16, 21, 24, 22, 18, 20, 24, 27, 22, 28, 27, 20, 20, 18, 15, 28, 24, 29];

fd.validators.push({
name: 'Mask validationr',
error: 'Please complete the IBAN',
validate:function(value){
    var eneteredValue = fd.field('IBAN').value.replace(/_/g, '');
    for(var i=0; i < IBANlength.length; i++){
        if(fd.field('IBAN').value < IBANlength[i].length){
            return false;
        }
        return true;
        }
    }
});

Dear @Sternchen,
What's the condition here? Should it be exactly the length of these values in the array? Why do they repeat? Why not check for the minimal length instead?

Each value represents one IBAN length from one country.
For Germany this would be 22, depending on which country is selected. So you have to enter a minimum and a maximum of 22 characters. Unfortunately, it also counts the dashes to the length.
Is there a possibility to intercept this?
I am open to all ideas.
An error message should be displayed if the IBAN has more than a length of 2 but less than what is in the array at this position.

Dear @Sternchen,
Not sure how would you ensure what position correlates to what country. Is the Country selected somewhere on the form as well?

Yes, there is a dropdown field where you select the country.
The country then determines what is in the maskedinput field. That means the maximum length and the first letters of the IBAN.


It looks like this and works really good.
image
Now only check if what is entered is the same as the masked input or if it is padded with "_".
These shouldn´t be allowed.
image

Dear @Sternchen,
You can have a validator to check if there are any underscores left, like this:

fd.field('IBAN').addValidator({
    name: 'IBAN validator',
    error: 'Fill out the IBAN completely',
    validate:function(value){
        return value.indexOf('_') < 0
    }
});

This looks much easier than what I did.
It seems like it´s working. Thank you.