Jump to content
Stef's Coding Community

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


Recommended Posts

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
Link to post
Share on other sites
  • Drew2 changed the title to How I got Phone Validation working in Ch1 Form Validation with PHP and JS: Adding jQuery Validation (section 2)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...