...
Phone Dash
This custom javascript automatically inserts dashes as the user enters a phone number into a Phone control. Characters other than the dash entered into the control are deleted. Add PhoneInsert to the CSS Class property of the Phone control to enable this JavaScript.
Code Block | ||
---|---|---|
| ||
var CustomEventHandlers = { setup: function (el) { if (CustomView.hasClass(el, 'PhoneInsert')) { FEvent.observe(el, 'keydown', this.formatPHONE.bindAsObserver(this, el)); FEvent.observe(el, 'keyup', this.formatPHONE.bindAsObserver(this, el)); } }, formatPHONE: function (event, element) { if (event.keyCode != 46 && event.keyCode != 8) { fldVal = $(element).value; var nom = fldVal.charAt(fldVal.length - 1); if (isNaN(nom) && nom != "-") { $(element).value = fldVal.substring(0, fldVal.length - 1); } else { if ((fldVal.length == 3) || (fldVal.length == 7)) { $(element).value = fldVal + "-"; } if (fldVal.length > 12) { $(element).value = fldVal.substring(0, fldVal.length - 1); } } } } } |