Jump to content

How I got Phone Validation working in Ch1 Form Validation with PHP and JS: Adding jQuery Validation (section 2)


Recommended Posts

Posted (edited)

In the course, we are asked to copy and paste code that validates a US phone number.  I was unable to find the exact page used in the course.

However, I found another page with code that produces the same result.  Here is the page: https://jqueryvalidation.org/phoneUS-method/

Here is the code that makes it all work (the bold portions are what I copy and pasted in):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>    
        <title>Validation Example</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        
        <script type="text/javascript" src="jquery.js"></script>  
        <script type="text/javascript" src="validate.js"></script>  
        <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
        
        <script type="text/javascript">
            $(document).ready(function(){
                jQuery.validator.setDefaults({
                debug: true,
                success: "valid"
                });
                $( "#phone" ).validate({
                rules: {
                    field: {
                    required: true,
                    phoneUS: true
                    }
                }
                });

                $("#form").validate();
            });
        </script>

Edited by Drew2
  • Drew2 changed the title to How I got Phone Validation working in Ch1 Form Validation with PHP and JS: Adding jQuery Validation (section 2)
  • 3 months later...
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...