2009-05-08

Replace non-digit symbols with RegEx

If you need to restrict input in nvarchar field(only the digit symbols for example), you may write some code to OnSave() event.
This code is replace all of non-digit symbols in new_telephonenumber field to nothing, i.e. "".


//before: new_telephonenumber = "555-555$#5"
//after: new_telephonenumber = "5555555"

var re = /\D/g;
if(document.crmForm.all.new_telephonenumber.DataValue != null){
crmForm.all.new_telephonenumber.DataValue = crmForm.all.new_telephonenumber.DataValue.replace(re,"");
}

Комментариев нет: