Phone Input Field
How do I make an phone input field?
Phone numbers should never be validated in a web form because there are too many formats that vary from place to place. This code shows how to let a user type anything they want and then ultimately convert it to only numbers which can be typed on a phone. What is a phone input field? How do you make a phone input field? This script and codes were developed by Dave Alger on 11 August 2022, Thursday.
Phone Input Field - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Phone Input Field</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <body ng-app> <label for="pN">Phone number:</label> <input id="pN" type="text" value="1-800-CALL-MOM"></input>
<div style="height: 10px; border-bottom: 1px dotted silver;margin-bottom: 10px;"></div>
<div class="wrapper">PhoneNumberToDisplay: <div id="out1"></div></div>
<div class="wrapper">Letters Converted: <div id="out2"></div></div>
<div class="wrapper">PhoneNumberToDial: <div id="out3"></div></div> <div id="out4"></div> <div id="out3"></div>
</body> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Phone Input Field - Script Codes CSS Codes
* { font-family: sans-serif; padding: 4px; }
#out1,#out2,#out3 { color: #999; display: inline-block;}
#out1 { font-weight: bold;
}
Phone Input Field - Script Codes JS Codes
var phoneLetterToDigit = ['2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','7','7','7','8','8','8','9','9','9','9'];
var raw = '';
var digitsReplaced = '';
var numbersOnly = '';
$('#pN').keyup(function () { update();
});
function update() { raw = $("#pN").val(); digitsReplaced = ''; $.each(raw.split(''), function(a,b) { var l = b.toUpperCase().charCodeAt(0) - 65; if (l >= 0 && l <= 25) { digitsReplaced += phoneLetterToDigit[l]; } else { digitsReplaced += b; } }); numbersOnly = digitsReplaced.replace(/[^0-9.]/g,''); $("#out1").html(raw); $("#out2").html(digitsReplaced); $("#out3").html(numbersOnly);
}
update();
Developer | Dave Alger |
Username | run-time |
Uploaded | August 11, 2022 |
Rating | 3 |
Size | 2,255 Kb |
Views | 34,408 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
The Ultimate Canvas Compression | 6,183 Kb |
Rainbow Spider | 7,749 Kb |
Slow Motion Shatter | 3,326 Kb |
Editable Fire Text | 3,997 Kb |
Simple Yin Yang | 5,396 Kb |
03 - CSS Variables | 2,682 Kb |
Catapult Game | 3,109 Kb |
JavaScript Fingerprint | 13,935 Kb |
A Pen by Dave Alger | 272,032 Kb |
Fireflies | 2,940 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Sketchy Box | Mnicpt | 3,033 Kb |
AngularJS Animated Todo List | Ehaase | 2,975 Kb |
Animated Vertical CSS3 Menu Black | MaCeLMp4 | 2,750 Kb |
Weather App | OmranAbazid | 2,596 Kb |
Playing with FlexBox | _Billy_Brown | 3,162 Kb |
Tic Tac Toe | Volv | 4,862 Kb |
Mobile Sub Menu Concept | Berdejitendra | 2,790 Kb |
Sort the Knowlege | Eprouver | 3,915 Kb |
Button fills | Zubfatal | 5,205 Kb |
Voting App - register | MatheusLima92 | 1,948 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!