I have a view page where i’m validating fields using knockout.js . I want to validate my fields in different country’s language like spanish,french etc i.e using localization.
I have added el-GR.js ,fr-FR.js , ru-RU.js etc files into my js folder and referenced them.
Now how can i validate or check into my modalModal.js page?
modalModal.js
ko.validation.rules.pattern.message = 'Invalid.';
ko.validation.configure({
registerExtenders : true,
messagesOnModified : true,
insertMessages : true,
parseInputAttributes : true,
messageTemplate : null
});
var mustEqual = function (val, other) {
return val == other();
};
var modalViewModel= {
firstName : ko.observable().extend({
minLength : 2,
maxLength : 40
}),
lastName : ko.observable().extend({
minLength : 2,
maxLength : 10
}),
organisation : ko.observable().extend({
minLength : 2,
maxLength : 40
}),
email : ko.observable().extend({ // custom message
email: true
}),
password: ko.observable()
};
modalViewModel.confirmPassword = ko.observable().extend({
validation: { validator: mustEqual, message: 'Passwords do not match.', params:
modalViewModel.password }
});
modalViewModel.errors = ko.validation.group(modalViewModel);
// Activates knockout.js
ko.applyBindings(modalViewModel,document.getElementById('light'));
I’ve done this for my latest KO project
I override the KO validation rules and use the Globalize plugin, like
edit: btw, there is a bug in the Globalize plugin, it will accept dot (.) as part of a number even if it isn’t, i fixed that like this