Password strength regular expression

Hello,

I am using the following to validate password, but get an error invalid regular express - unterminated group

validate:"^(?=.?[A-Z])(?=(.[a-z]){1,})(?=(.[\d]){1,})(?=(.[\W]){1,})(?!.*\s).{8,}$"

any help would be appreciated

Kris

Hi

please attach complete init part and pwd examples

Here’s the code

var dhxLayout = new dhtmlXLayoutObject("layoutObj", "2U");
    var myForm = dhxLayout.cells("a").attachForm([
         {type:"settings",position:"label-left",labelWidth:110,inputWidth:200},
         {type: "input", name:"strUserName",label: "User Name"},
         {type:"password",label:"Password",name:"strPassword",maxLength:50,
            validate:"^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$",required:true,
            note:{text:"Password must have a minimum of 8 characters at least 1 Alphabet, 1 Number and 1 Special Character"}
         }
         {type: "label", list: [
            {type: "button", value:"Change",name:"btnChange",offsetLeft:200},
            {type: "newcolumn"},
            {type: "button", value:"Cancel",name:"btnCancel"}
            ]}
    ]); //end form

Hi

first, you need to update your regexp a bit, inside form it parsed with new RegExp(), so you need to add extra slashes to you regexp string, i.e.:
validate: “^(?=.?[A-Z])(?=(.[a-z]){1,})(?=(.[\d]){1,})(?=(.[\W]){1,})(?!.*\s).{8,}$”

second, inside a form there can be several validate options and if validate value is string - form try to split it by comma, in your case finally you have several validate rules attached to a password field. to prevent this behaviour you need to set separator (for split) manually, for this use the following init (i.e. load form struct after separator updated):

var myForm = dhxLayout.cells("a").attachForm(); myForm.separator = null; // or any string value which is not included into your validate rule myForm.load([....]);