Last active
August 29, 2015 14:01
-
-
Save salsalabs/c2d3997152516754858b to your computer and use it in GitHub Desktop.
Validate at US phone number input field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
// FIELD_NAME can be Phone, Cell_Phone or the API name of a custom supporter field. | |
$('input[name=FIELD_NAME]').blur(function() { | |
if (!RegExp('\\d{3}-\\d{3}-\\d{4}').test($(this).val())) { | |
alert('Please provide a phone number like NNN-NNN-NNNN.'); | |
return false; | |
} | |
return true; | |
}) | |
}) | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment