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

LVL 12
Nathan RileyFounderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
If you are adding "groups" dynamically, you need to check each one.  Try:
                        <script>
                            $('.add-priv-co').submit(function () {
								var returnOK=true
                                var setFBurl = "www.facebook.com/";
								
								$('.facebookURL').each(function(){
                                    // Get the Login Name value
                                    var name = $(this).val();
    
                                    // trim it
                                    name = $.trim(name);
    
                                    //make it all lowercase
                                    name = name.toLowerCase();
    
                                    if (name.indexOf(setFBurl) < 0){
                                        returnStatus=false;
                                        setTimeout(function() { alert('Please enter a correctly formatted Facebook URL.'); }, 100);
                                    }
								});
							return returnStatus;
                            });
                        </script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.