I have a datagrid that contains data from different documents. The user can edit some of the columns. I want to restrict them to only be able to enter a number.
I would like to do it from the client side instead of server side as that would mean checking 20 or more documents.
ok figured out what to do. Create a function to format the data with as red background if they enter a non-numeric or invalid value. Put the function in a scriptBlock and put the name in the formatter field for each column
function ValidNmbr(s)
{
var RegularExpression = new RegExp(/^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/);<br/>
if(RegularExpression.test(s))
{
return s;
}
else {
return "<span style='background-color:red'>"+s+"</span>";
}
}
Client side format enforcement can be bypassed (anyone having firebug), so you have to be clear it is only for the comfort of the user, not for the integrity of your data.
On the server side: you can have a entry field with a number mask. No code required — might be the least work. If you want to do that client side:
Hope that helps