Show Error Message

escanor
Giga Contributor

 I have 2 client scrip like below for my register form

//Date of birth check function onSubmit()

function onSubmit() {
	//Type appropriate comment here, and begin script below
	var DoB = new Date(g_form.getValue('date_of_birth'));
	var CurrentDate = new Date();
	if(CurrentDate <= DoB) {
		g_form.addErrorMessage("Re-enter your DoB");
		g_form.clearValue('date_of_birth');
		return false;
	}
}

//Password check

function onSubmit(){
	
	//Type appropriate comment here, and begin script below
	var regex = /(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@#$%^&+=])/g;
	var test_string = g_form.getValue('password');
	var min_len = 8;
	var valid = regex.test(test_string);
	if(!valid && test_string.length < 8){
		g_form.addErrorMessage("Password must be at least 8 characters long and contain: 1 Uppercase Letter, 1 Lowercase Letter, 1 Number, 1 Special Character.");
		g_form.clearValue('password');
		return false;
	}
	return true;
}

This is my register screen
find_real_file.png

The 1st error mess doesn't disappear when another one appear. I'm a new guy with servicenow. Can you guys help me ? Thank you 

 

 

1 ACCEPTED SOLUTION

Try the below

 

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

var inputtext = g_form.getValue('password'); //Lets assume the variable name is 'Password
var answer = true;
var param = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).{8,15}/;
//The password will take character in between 8-15 and will must consist at least one small character. one capital character, one digit and any special character among @#$%^&+=.
if(!inputtext.match(param))
{
g_form.showFieldMsg('password','Enter valid password','error');
answer= false;
}
else
{
g_form.hideFieldMsg('password');
}
}

Regards
Harish

View solution in original post

7 REPLIES 7

Harish KM
Kilo Patron
Kilo Patron

share the code of both client script plz

Regards
Harish

i just edited my post like above ! 

you need to use 2 onChange client scripts. Use the same code and run it onchange for those 2 variables

//Type appropriate comment here, and begin script below

var DoB = new Date(g_form.getValue('date_of_birth'));

var CurrentDate = new Date();

if(CurrentDate <= DoB) {

g_form.addErrorMessage("Re-enter your DoB");

g_form.clearValue('date_of_birth'); r

//return false; //not needed since it will show error message

}

 

//Type appropriate comment here, and begin script below

var regex = /(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@#$%^&+=])/g; 

var test_string = g_form.getValue('password');

var min_len = 8;

var valid = regex.test(test_string);

if(!valid && test_string.length < 8){

g_form.addErrorMessage("Password must be at least 8 characters long and contain: 1 Uppercase Letter, 1 Lowercase Letter, 1 Number, 1 Special Character.");

g_form.clearValue('password');

//return false;

//return true;

Regards
Harish

Can you help me to check Password check script ! I think it's wrong somewhere