My displayFormat pattern is "$###,###,###;-$###,###,###;#" (although it can vary) and I am looking to reformat the value in an AspxTextbox by removing commas on the 'GotFocus' and 'LostFocus' events. This can be achieved by calling the following JavaScript function:
function TextBoxFormat(ctrl, e, displayFormat, charactersToRemove) {
var value = ctrl.GetValue();
var i;
if (value != null && charactersToRemove != null) {
for (i = 0; i < charactersToRemove.length; i++)
value = value.replace(charactersToRemove[i], '');
ctrl.SetValue(ASPxFormatter.Format('{0:' + displayFormat + '}',
parseInt(value)));
}
I attempted to use ASPxFormatter, but it is an internal class not intended for user projects. Additionally, using
String.Format('{0:' + displayFormat + '}', parseInt(value)));
did not work as expected. It threw an exception because String.format
does not accept this specific format of pattern.
Could you please suggest a method to reformat my string to any desired pattern, rather than being restricted to the one I originally described?
Your assistance would be greatly appreciated....