You need to avoid backslashes, otherwise javascript will treat your single backslash as an escape character for the next character. This is because it is a string, not a regular expression literal.
: , , :
http://jsfiddle.net/antishok/ED3Mh/2/
self.ContactPhone = ko.observable().extend({
required: true,
pattern: {
message: 'Invalid phone number.',
params: /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/
}
});
params: '^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$'