Field Validator - Number & Leading 0s

Developer
Size
1,973 Kb
Views
14,168

How do I make an field validator - number & leading 0s?

Two examples of jQuery implementation of field validation. It only allows numerical input (both row and keypad) and will add leading 0s (up to 10 digits) to the entered value. . What is a field validator - number & leading 0s? How do you make a field validator - number & leading 0s? This script and codes were developed by Casey Hunt on 19 November 2022, Saturday.

Field Validator - Number & Leading 0s Previews

Field Validator - Number & Leading 0s - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Field Validator - Number & Leading 0s</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <form> <input type="text" id="text" maxlength="10" /> <input type="text" id="text2" maxlength="10" />
</form> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Field Validator - Number & Leading 0s - Script Codes CSS Codes

body { background-color: #ccc;
}

Field Validator - Number & Leading 0s - Script Codes JS Codes

$('#text').keydown(function (event) { if (event.keyCode > 57) { if (event.keyCode < 96 || event.keyCode > 105) { event.preventDefault(); } }
});
$('#text').blur( doPad(10) );
function doPad(length) { return function() { var str = this.value; while (str.length < length) { str = '0' + str; } this.value = str; }
}
/////////////////////////////
// Way sexier way to do it //
$('#text2').on('blur', { to: 10 }, pad );
function pad(e) { var val = this.value + ''; this.value = Array( e.data.to - ( val.length - 1 ) ).join('0') + val;
}
Field Validator - Number & Leading 0s - Script Codes
Field Validator - Number & Leading 0s - Script Codes
Home Page Home
Developer Casey Hunt
Username caseymhunt
Uploaded November 19, 2022
Rating 3
Size 1,973 Kb
Views 14,168
Do you need developer help for Field Validator - Number & Leading 0s?

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!

Casey Hunt (caseymhunt) Script Codes
Create amazing art & images with AI!

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!