Link to home
Start Free TrialLog in
Avatar of Nathan Riley
Nathan RileyFlag for United States of America

asked on

Validation on Form Input Field

I have the following code that I'm trying to verify that the www.facebook.com/ is in the URL the user inputs.  It's not working for some reason.  

Here is my html and jquery.
<form class="col-md-12 add-priv-co" action="submit.php" method="post" style="margin-top:20px;margin-bottom:20px;">

                        <label>Competitor Links</label>

                            <div class="form-group rssRow">
                                <span onclick="this.parentNode.parentNode.removeChild(this.parentNode)">X</span>
                                <div class="col-md-6 noPadLeft">
                                    <input class="form-control" name="title[]" placeholder="Competitor Name" />
                                </div>
                                <div class="col-md-6 noPadLeft">
                                    <input class="form-control facebookURL" name="link[]" placeholder="Link" />
                                </div>
                                <div class="clearfix"></div>
                            </div>

                            
                        <input type="hidden" name="submitType" value="25"/>
                        <input type="hidden" name="userID" value="<?php echo $userID;?>"/>
                        <input type="hidden" name="orgID" value="<?php echo $orgID;?>"/>

                        <input type="button" class="btn loginBTN pull-right" id="add-row" name="add-row" value="ADD ROW" />
                        <button class="btn loginBTN">SAVE</button>
                        <script>
                            $('.add-priv-co').submit(function () {
                                var setFBurl = "www.facebook.com/";

                                // Get the Login Name value
                                var name = $('.facebookURL').val();

                                // trim it
                                name = $.trim(name);

                                //make it all lowercase
                                name = name.toLowerCase();

                                if (name.indexOf(setFBurl) < 0){
                                    setTimeout(function() { alert('Please enter a correctly formatted Facebook URL.'); }, 100);
                                    return false;
                                }

                            });
                        </script>
                    </form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial