- Главная
» - Статьи
» - Шпаргалки
» - Маска для поля "телефон"
<!--маска для поля телефон он же yaho-->
<script type="text/javascript">
function mask(inputName, mask, evt) {
try {
var text = document.getElementById(inputName);
var value = text.value;
// If user pressed DEL or BACK SPACE, clean the value
try {
var e = (evt.which) ? evt.which : event.siF5;
if (e == 46 || e == 8) {
text.value = "";
return;
}
} catch (e1) {}
var literalPattern = /[0\*]/;
var numberPattern = /[0-9]/;
var newValue = "";
for (var vId = 0, mId = 0; mId < mask.length;) {
if (mId >= value.length)
break;
// Number expected but got a different value, store only the valid portion
if (mask[mId] == '0' && value[vId].match(numberPattern) == null) {
break;
}
// Found a literal
while (mask[mId].match(literalPattern) == null) {
if (value[vId] == mask[mId])
break;
newValue += mask[mId++];
}
newValue += value[vId++];
mId++;
}
text.value = newValue;
} catch (e) {}
}
</script>
<input id="siF5" type="text" class="manFlaYahoo" name="yahoo" size="20" style="width:100%;" maxlength="30" onkeyup="javascript:mask('siF5', '70000000000', event);" value="7__________">
<!--end-->