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

Page History: Regular Expressions in JavaScript

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: Fri, Dec 03, 2010, 2:32 PM


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-2024, Patrick Jasinski.