Phone regular expression
Phone regular expression
anithanokku
Posts: 3Questions: 1Answers: 0
I want to do a phone validation before inserting data to database., how can i use a regular expression, do data tables support an inbuilt feature to support phone / zip code validations. I could only set the required field validation. Following is the code
editor.on('preSubmit', function (e, o, action) {
var BusinessName = editor.field('BusinessName');
var PostalCode = editor.field('PostalCode');
var iPhone = editor.field('iPhone');
if (!BusinessName.val()) {
BusinessName.error('BusinessName must be given');
}
if (!PostalCode.val()) {
PostalCode.error('PostalCode must be given');
}
if (!iPhone.val()) {
iPhone.error('A phone number must be given');
}
if (this.inError()) {
return false;
}
});
Is there a property that could be set in ipOpts for phone field validation and zip field validation.
Thanks.
This discussion has been closed.
Replies
Hi,
Editor focuses on validation on the server-side since validation must be done there anyway. Under the assumption that the Ajax query is fairly fast to process, generally I would suggest doing the validation at the server only rather than duplicating the effort.
At the server-side you can use the validation methods. There isn't a built in validation method for telephone numbers since the format of them can vary significantly throughout the world. As such you'd need to use a custom validation method as described on that page.
If you need to do it on the client-side, you would use a regular expression in Javascript as normal on the phone number field - similar to the validation you have above.
Regards,
Allan
Hi Allan,
Thanks for the link .. I have already tried the .NET validation as mentioned in https://editor.datatables.net/manual/net/validation b
Following is the way I am using it but it still doesn't validate
Code:
Thanks.
There is no
validator
option on the client-side. As I tried to explain above, Editor focuses on server-side validation. As the documentation shows shows, the validation is applied in the C# code, not Javascript as you have tried to do above.Allan