My favorites | Sign in
Project Logo
          
Search
for
Updated Feb 17, 2008 by doug.sparling
Labels: Featured
Documentation  

jquery.regexpCommon.js - jQuery plugin to provide commonly used regular expressions.

Introduction

Details

Example

<!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>
  <title>jquery regexpCommon</title>

  <script type="text/javascript" src="jquery-1.2.1.min.js"></script>
  <script type="text/javascript" src="jquery.regexpCommon.js"></script>

  <script type="text/javascript">

    $(function($) {
      var message;

      var ssn = '123-45-6789';
      if ( ssn.match($.regexpCommon('ssn')) ) {
       message = ssn + " is a SSN<br/>"
      }

      var url = 'http://jquery.com/';
      if ( url.match($.regexpCommon('url')) ) {
       message += url + " is a URL<br/>";
      }

      var email = 'blah@blah.com';
      if ( email.match($.regexpCommon('email')) ) {
       message += email + " is a valid email address<br/>";
      }

      var phone = '(555)555-5555';
      if (phone.match($.regexpCommon('phoneNumberUS')) ) {
       message += phone + " is an US phone number<br/>";
      }

      var zip = '12345-1111';
      if (zip.match($.regexpCommon('zipCodeUS')) ) {
       message += zip + " is an US zip code<br/>";
      }

      var currencyUS = '$1,000.00';
      if (currencyUS.match($.regexpCommon('currencyUS')) ) {
       message += currencyUS + " is a US currency<br/>";
      }

      var htmlHex = '#ffffff';
      if (htmlHex.match($.regexpCommon('htmlHexCode')) ) {
       message += htmlHex + " is an HTML Hex code<br/>";
      }

      var quadIP = '127.0.0.1';
      if (quadIP.match($.regexpCommon('dottedQuadIP')) ) {
       message += quadIP + " is a Quad IP Address<br/>";
      }

      var macAddress = '08:00:69:02:01:FC';
      if (macAddress.match($.regexpCommon('macAddress')) ) {
       message += macAddress + " is a MAC Address<br/>";
      }

     $('#message').html(message);
    });

  </script>

</head>

<body>

<div id='message'></div>

</body>
</html>


Comment by zerosharp, Apr 16, 2008

sadasd


Sign in to add a comment
Hosted by Google Code