Knockout validation - to match starts with specific characters

248 Views Asked by At

I have to validate if an ID starts with a specific set of characters, followed by alphanumeric values. I am using knockout validation.

I have the code here,

var value_id = ko.observable('').extend({
            minLength: 18,
            maxLength: 18,
            pattern: {
              params: '/^(xyz34|xyz12)((?=.*[a-zA-Z])(?=.*[0-9])){13}/g',
              message: 'Please provide a valid ID.'
            },
            required: {
              message: 'Please enter a ID.',
              params: true
            }
          });

The same pattern is working fine in online regex tester.

Any suggestion would be helpful.

0

There are 0 best solutions below