Domain Validation In Angular And SQL Server Constraint

Introduction:Domain Validation in AngularJS and SQL Server constraint.


First refer to this code in your cshtml page .

  1. <form name="Myform" data-toggle="validator">  
  2.     <div class=" col-xs-4 ">  
  3.         <div class="form-group"> <label>Domain Name<span class="required" style="color:red"> *</span><br /></label> <input type="text" id="domainbind" name="domainbind" ng-model="domain_name" required ng-change="CheckDomainchange(domain_name)" ng-pattern="Pattern" class="form-control ng-untouched" placeholder="Add Domain," maxlength="150"> <span ng-show="Myform.domainbind.$error.pattern" style="color:#d9831f;">Enter Valid Domain</span> </div>  
  4.     </div>  
  5. </form>  

Step 2

Domain validate without (www) and (www.) for Ex: user likes or so  to validate prefix www and Angularjs. I have to assign ng-change for Domain validation purposes in Angularjs controller page and ng-pattern for our format of string validations.

Kindly check below code,

Step 3

  1. $scope.Pattern = /^([\w-]+(?:\.[\w-]+)*)((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{1,6}(?:\.[a-z]{2})?)$/i;  


Pattern purpose validates our string prefix www or www. And adds valid domain.


After user entered valid string


Step 4

SQL Server prefix Constraint validation in database.

Goto SQL Server ->select your database and Expand any one table and any one Column also select Constraint Folder.

Right click Constraint Folder add New Constraint


Add Expression of below code for prefix www or www. Validations in database constraint.

(substring([domain_name],(1),(4))<>'www.' AND substring([domain_name],(1),(3))<>'www').

I hope this blog realy helps you add and domain validate in AngularJS and SQL server constraint.