When using a string to define a regular expression, you need to avoid any backslashes, so it should be:
self.username = ko.observable(data.username || null)
.extend({ required: true, maxLength: 50 })
.extend({ pattern: { message: 'Username cannot contain spaces.', params: '^\\S*$' } });
If you use a regular expression literal instead of a string, you don't need to hide the backslash:
self.username = ko.observable(data.username || null)
.extend({ required: true, maxLength: 50 })
.extend({ pattern: { message: 'Username cannot contain spaces.', params: /^\S*$/ } });
source
share