Jump to content

can i auto make - in phone field?


flemingmike

Recommended Posts

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript">
function formattel() {
var element = document.getElementById("tel");
element.onkeypress = function() {
	var length = element.value.length;
	if(length == 9) {
		var reg = new RegExp("^[-]?[0-9]+[\.]?[0-9]+$");
		if(reg.test(element.value)) {
			var tel = element.value;
			element.value = tel.substring(0,3)+"-"+tel.substring(3,6)+"-"+tel.substring(6,10);
		}
	}
}
}
window.onload = function() {
formattel();
}
</script>
</head>
<body>
Tel: <input type="text" name="tel" id="tel" maxlength="12" size="12" />
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.