esnextbin sketch
made with esnextbin
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
function onChange(control, oldValue, newValue, isLoading) {
// If the newValue is empty, display a message letting the user know the correct formats and that the field is required
if(isLoading || newValue === ''){
return;
}
// If the newValue is the same as the oldValue, alert the user it cannot be the same value as the previously entered value
if (newValue == oldValue) {
g_form.addInfoMessage('Please update the value from another value other than the previously entered value');
return;
}
// If the newValue is a completely new value,
// If the newValue is a completely new value,
if (newValue) {
if (newValue != oldValue) {
var x = newValue;
if (x.length == 4) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{4})/, 'ext $1');
g_form.setValue('u_phone_number', x);
} else if (x.length == 10) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
g_form.setValue('u_phone_number', x);
} else if (x.length == 11) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{1})(\d{3})(\d{3})(\d{4})/, '($2) $3-$4');
g_form.setValue('u_phone_number', x);
} else if (x.length == 14) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{1})(\d{3})(\d{3})(\d{4})(\d{4})/, '($2) $3-$4 ext$5');
g_form.setValue('u_phone_number', x);
} else if (x.length == 15 || x.length == 16 || x.length == 17 || x.length == 18 || x.length == 19 || x.length == 20 || x.length == 21 || x.length == 22 || x.length == 23 || x.length == 24 || x.length == 25 || x.length == 26 || x.length == 27 || x.length == 28 || x.length == 29 || x.length == 30 || x.length == 31 || x.length == 32 || x.length == 33 || x.length == 34 || x.length == 35 || x.length == 36 || x.length == 37 || x.length == 38 || x.length == 39 || x.length == 40) {
g_form.setValue('u_phone_number', "");
g_form.addInfoMessage('The phone number cannot be blank. Please use one of these formats: ###-###-####, (###) ###-####, ###-###-#### ext ####, (###) ###-#### ext ####, ext ####');
}
}
}
}
{
"name": "esnextbin-sketch",
"version": "0.0.0"
}
'use strict';
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
function onChange(control, oldValue, newValue, isLoading) {
// If the newValue is empty, display a message letting the user know the correct formats and that the field is required
if (isLoading || newValue === '') {
return;
}
// If the newValue is the same as the oldValue, alert the user it cannot be the same value as the previously entered value
if (newValue == oldValue) {
g_form.addInfoMessage('Please update the value from another value other than the previously entered value');
return;
}
// If the newValue is a completely new value,
// If the newValue is a completely new value,
if (newValue) {
if (newValue != oldValue) {
var x = newValue;
if (x.length == 4) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{4})/, 'ext $1');
g_form.setValue('u_phone_number', x);
} else if (x.length == 10) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
g_form.setValue('u_phone_number', x);
} else if (x.length == 11) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{1})(\d{3})(\d{3})(\d{4})/, '($2) $3-$4');
g_form.setValue('u_phone_number', x);
} else if (x.length == 14) {
x = x.replace(/[^\d\s]+/g, '');
x = x.replace(/(\d{1})(\d{3})(\d{3})(\d{4})(\d{4})/, '($2) $3-$4 ext$5');
g_form.setValue('u_phone_number', x);
} else if (x.length == 15 || x.length == 16 || x.length == 17 || x.length == 18 || x.length == 19 || x.length == 20 || x.length == 21 || x.length == 22 || x.length == 23 || x.length == 24 || x.length == 25 || x.length == 26 || x.length == 27 || x.length == 28 || x.length == 29 || x.length == 30 || x.length == 31 || x.length == 32 || x.length == 33 || x.length == 34 || x.length == 35 || x.length == 36 || x.length == 37 || x.length == 38 || x.length == 39 || x.length == 40) {
g_form.setValue('u_phone_number', "");
g_form.addInfoMessage('The phone number cannot be blank. Please use one of these formats: ###-###-####, (###) ###-####, ###-###-#### ext ####, (###) ###-#### ext ####, ext ####');
}
}
}
}