@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowSorting()
----------
})
.Columns(col =>
{
---------------
col.Field("Phone").HeaderText("Phone").ValidationRules(v => v.AddRule("required", true).AddRule("maxlength", 6).AddRule("minlength", 6)).TextAlign(TextAlign.Right).Width(75).Add();
})
) |
ValidationRules
property of Columns
. Hello. Is there a way to validate a phone number? I have been doing the ff_valuenotempty, but it will accept anything someone puts there. Is there a way to see if its a number?
I think the easiest way would be to check that it is the appropriate number of digits, with no spaces, but I understand the integer validation only checks to see if its an integer, not one of a specific length.
Any thoughts?
Hi oddssatisfy,
Query: Is there a way to validate a phone number? I have been doing the ff_valuenotempty, but it will accept anything someone puts there. Is there a way to see if its a number?
@(Html.EJ().Grid<object>("HierarchyGrid")
…. .Columns(col => { … col.Field("PhoneNumber").HeaderText("Phone number").Width(110).ValidationRules(v => v.AddRule("required", true).AddRule("digits", true).AddRule("maxlength", 10).AddRule("minlength", 10)).Add(); }) |
In the above code snippet, we used the digits validation rule and the maxlength and minlength validation rules. When using the digits validation rule, you can only enter the digit .
Please refer to the below sample,
Please refer to the below help documentation,
https://help.syncfusion.com/aspnetmvc/grid/editing?cs-save-lang=1&cs-lang=razor#column-validation
https://jqueryvalidation.org/digits-method/
And you can also add your own custom
validation methods for a specific column. Function
call to custom validator function to be mentioned within ValidationRules
property of Columns.
Please
refer the below document and online sample.
https://help.syncfusion.com/aspnetmvc/grid/editing#custom-validation
http://mvc.syncfusion.com/demos/web/grid/customvalidation
Regards,
Pon selva
If this post is helpful, please consider
Accepting it as the solution so that other members can locate it more quickly.