PDA

View Full Version : Brazilian phone number format



RaphaelSaldanha
Dec 31, 2014, 4:21 AM
In brazil we have both 8-digit and 9-digit format, so i would like to provide an example of using InputMask to accomplish this requirement


<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<script type="text/javascript">
var ProcessMask = function (item, newValue, oldValue) {
var newMask = null;
var eightDigitFormat = "(~~) ~999-9999?9";
var nineDigitFormat = "(~~) ~9999-9999";

if (item.inputMask.getUnmaskedValue().length < 11) {
newMask = eightDigitFormat;
}
else {
newMask = nineDigitFormat;
}

if (item.inputMask.mask != newMask) {

item.suspendEvents();

item.inputMask.setMask(newMask);

item.resumeEvents();
}
}
</script>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:TextField FieldLabel="Brazilian Phone" AllowBlank="false" runat="server">
<Plugins>
<ext:InputMask Mask="(~~) ~999-9999?9" ClearWhenInvalid="false" runat="server">
<MaskSymbols>
<ext:MaskSymbol Name="~" Regex="[1-9]" />
</MaskSymbols>
</ext:InputMask>
</Plugins>
<Listeners>
<Change Fn="ProcessMask" />
</Listeners>
</ext:TextField>
</body>
</html>


Daniil, if you have nothing to add, please mark this thread as closed.

Daniil
Jan 07, 2015, 1:54 PM
Raphael, thank you for sharing!

I've moved the thread to the Examples and Extras forum.

RaphaelSaldanha
Jan 07, 2015, 3:04 PM
Thank you Daniil.