Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Regular Expressions in JavaScript

RSS
Modified on Wed, Jan 19, 2011, 2:18 PM by Administrator Categorized as JavaScript, jQuery, and Angular, Regular Expressions
The following code demonstrates how to use regular expressions in JavaScript

<html>
<head>
<script type='text/javascript'>
function ValidateTime(input)
{
    var regex3 = /^(1[0-2]|\d)\:\d{2}\s{0,}[APap][Mm]$/;
    return input.match(regex3);
}
function input_click()
{
    var input = document.getElementById('input').value;
    if (ValidateTime(input))
        alert('[' + input + '] is a valid time');
    else
        alert('[' + input + '] is NOT a valid time');
}
</script>
</head>
<body>
Start Time: <input type='input' id='input' />
<br/>
<input type='submit' value='Test' onclick='input_click();' />
</body>
</html>

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2018, Patrick Jasinski.