1

I have a field that accepts a URL. How do I validate this URL in angularjs.

<div class="controls">
   <input type="text" ng-model="controller.data.PropertyWebsite"/>
</div>

Any ideas and suggestions are appreciated !!!!

2

2 Answers 2

1

Add a html input[url] to a form and mark it as required, then use angular to check if the form is valid or not:

html:

<form name="form">
    <tr>
        <td><input type="url" name="url" required></td>
    </tr>
    <tr>
        <td><button type="submit" ng-click="SubmitForm('form')">submit</button>                                    </td>
    </tr>
</form>

controller:

$scope.submitForm = function () {

    if (this.form.$invalid)
        //not valid
    } else {
        //valid
    }
}

More information about url input: https://docs.angularjs.org/api/ng/input/input%5Burl%5D

Sign up to request clarification or add additional context in comments.

Comments

0

You can use ng-pattern to validate against a RegEx. https://docs.angularjs.org/api/ng/directive/input

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.