Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

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

Ty bro ! I really apriciate that ! 

your welcome bro 🙂

Regards
Harish