Restrict Special Characters

rambabu1
Giga Expert

Hi 

I want to restrict special character / \during creation of use id in user form.

Please help if you have any idea.

7 REPLIES 7

It shows below error?

find_real_file.png

This is string variable so put the " "; 

var specialChar = "/\";

 

Thanks,

Ashish


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

AshishKM
Kilo Patron
Kilo Patron

Hi, You can use the code shared by @Priyanka Teke , the code is checking the restriction and alerting the user.

However you can set the regular expression 'what is allow' and check if input value is matched with regular expression or not.

find_real_file.png

 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    // configure all allow character
	var regex = new RegExp("^[a-zA-Z0-9]*$");
	// note: this IF has ! - means it is only considering character values given in regex - you can edit the regex
    if (!regex.test(newValue)) {
        alert('Incorrect username');      // Alert the User if input value not matched with regExp
        g_form.setValue('user_name', ''); // Set the User Id field empty
    }

}

 

Thanks,

Ashish

Please mark correct answer and helpful for others if it helps you


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution