client script for strong password validation using Regex.

Agent Arjun
Kilo Explorer

client script for strong password validation using Regex.

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Arjuna,

There must be some requirement i.e. what is strong password? combination of numbers and digits etc

check this link and sample script below

https://docs.servicenow.com/bundle/newyork-platform-administration/page/script/server-scripting/task...

Sample script below either have it as onChange or onSubmit

//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 @#$%^&+=.

function onSubmit() {

  var inputtext =   g_form.getValue('Password'); // give your field/variable name here

  var param = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).{8,15}/;  

  if(!inputtext.match(param))
  {
  alert('Please Provide Correct Password');
  return false;
  }
  else
  return true;
}



Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sumanth16
Kilo Patron

Hi Arjuna ,

 

Please go through below thread once:

https://community.servicenow.com/community?id=community_question&sys_id=e75f40dedb1d2b404abd5583ca96...

 

Please mark it as helpful if it helps.

 

Thanks,
Sumanth

Munender Singh
Mega Sage

Hi,

Please use the following client script:

type:onsubmit

script:

function onSubmit() {

var pswd = g_form.getValue('passwordfield'); // give your field/variable name here

var param = ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,});

if(!pswd.match(param))
{
alert('Kindly enter a strong password.');
return false;
}
else
return true;
}

---------------

Details of regex expressions being used:

^ The password string will start this way
(?=.*[a-z]) The string must contain at least 1 lowercase alphabetical character
(?=.*[A-Z]) The string must contain at least 1 uppercase alphabetical character
(?=.*[0-9]) The string must contain at least 1 numeric character
(?=.[!@#\$%\^&]) The string must contain at least one special character, but we are escaping reserved RegEx characters to avoid conflict
(?=.{8,}) The string must be eight characters or longer

 

Regards,

Munender