Jones King Jones King - 5 months ago 20x
Javascript Question

How to check if valit facebook url, before submit

I am looking for a way to check, if the url a user have posted in my form is a valid facebook url. I am aware of the regx


But how to use it, am i not sure on how to do?

<div class="col-sm-6">
<div class="col-sm-12">
<b>Facebook Url</b>
<input id="FacebookUrl" name="FacebookUrl" type="text" class="form-control" />

<div class="col-sm-12">
<button id="SendBtn" class="btn btn-success pull-right">Send</button>

How can i make a form validation on that, that checks the facebook regx? Thanks


In the button onclick event:

<button id="SendBtn" class="btn btn-success pull-right" onclick="return validateUrl();">Send</button>

And then you can open a script tag in the same file or other file and implement your regex.

function validateUrl() {
  url = $("#FacebookUrl").val();
  var pattern = /^(?:(?:http|https):\/\/)?(?:www.)?\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\-]*)?$/;
  if(pattern.test(url)) {
    alert("Correct URL");
  else {
    alert("Incorrect URL");
  return pattern.test(url);

And with this result prevent the action.