Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salsalabs/c2d3997152516754858b to your computer and use it in GitHub Desktop.
Save salsalabs/c2d3997152516754858b to your computer and use it in GitHub Desktop.
Validate at US phone number input field
<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