Text field that allows 10 digit numbers only without repetitive digits

Abhishek Barik
Tera Contributor

Hi Team,

We have a requirement to have a text field variable that doesn't allow more than 10 digits and also no repetitive numbers. Request you to please help in providing the client script for this.

find_real_file.png

Thanks in advance,

Abhishek

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi,

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var reg = /^(?:(.)(?!\1{9}))\d{9}$/;
    var ans = g_form.getValue('time_field'); //replace time_field with variable/field name
    if (!reg.test(ans)) {
        alert('Please enter valid non-repititive digits & 10 digits');
    }

}

View solution in original post

6 REPLIES 6

Jaspal Singh
Mega Patron
Mega Patron

Try something as below

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var reg = /^(?!.*(.).*\1)\d{10}$/;
    var ans = g_form.getValue('time_field'); //replace time_field with variable/field name
    if (!reg.test(ans)) {
        alert('Please enter valid non-repititive digits & 10 digits');
    }

}

Hi @Jaspal Singh ,

Thanks for the script, but the regex is not allowing numbers like "9848129660". My requirement is like not allowing numbers like "1111111111" 10 same digits shouldn't be repetitive if you see my screenshot example.

Could you please provide the updated script ?

Not sure but your question was 

Text field that allows 10 digit numbers only without repetitive digits.

 

Hitoshi Ozawa
Giga Sage
Giga Sage

If it's 10 same digits,

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var reg = /^(?:(.)(?!\1{9}))+$/;
    var ans = g_form.getValue('time_field'); //replace time_field with variable/field name
    if (!reg.test(ans)) {
        alert('Please enter valid non-repititive digits & 10 digits');
    }

}