Created
March 9, 2015 13:19
-
-
Save gangadharjannu/ec114a9bab5df6873abd to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/cigino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="myApp"> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="myController"> | |
<input type="text" ng-model="nospace" input-validation="restrictSpaces"> | |
<script id="jsbin-javascript"> | |
var app=angular.module("myApp", []); | |
app.controller("myController", function($scope){ | |
}); | |
app.directive('inputValidation', [ | |
function() { | |
return { | |
restrict : 'A', | |
require : 'ngModel', | |
link : function(scope, elem, attrs, ctrl) { | |
var pattern,flag=0,data=0; | |
elem.on('blur',function(e){ | |
switch(attrs.inputValidation) { | |
case "withTwoDigits": | |
modifyValues(); | |
break; | |
default: | |
break; | |
} | |
function modifyValues(){ | |
var a=$(e.currentTarget).val(); | |
if(a=="0.00"||a=='.00'){ | |
$(e.currentTarget).val(0); | |
} | |
if(a[0]=='.'&& typeof(a[1])=='undefined'){ | |
$(e.currentTarget).val(0); | |
} | |
else if(a[0]=='.'&& typeof(a[1])!='undefined'){ | |
$(e.currentTarget).val(0+a); | |
} | |
} | |
}); | |
elem.on('focusin',function(e){ | |
if(flag===0){ | |
flag=1; | |
data=$(e.currentTarget).val(); | |
} | |
else{ | |
} | |
}); | |
elem.on('focusout',function(){ | |
flag=0; | |
}); | |
elem.on('keyup', function(e) { | |
switch(attrs.inputValidation) { | |
case "restrictSpaces": | |
pattern = /^[a-zA-Z0-9]*$/; | |
pat1=/[^a-zA-Z0-9]/g; | |
break; | |
case "pwdCheck" : | |
pattern = /^[a-zA-Z0-9!@#%$^&*()]*$/; | |
pat1=/[ ]/g; | |
break; | |
case "onlyNumbers": | |
pattern=/^[0-9]*$/; | |
pat1=/[^0-9]/g; | |
break; | |
case "withTwoDigits": | |
pattern=/^[0-9]*(\.{1})?([0-9]{1,2})?$/; | |
pat1=/[^[]]/; | |
break; | |
default: | |
pattern = /^[^<>{}]*$/; | |
break; | |
} | |
if (!pattern.test($(e.currentTarget).val())) { | |
$(e.currentTarget).val(data); | |
} | |
else{ | |
data=$(e.currentTarget).val(); | |
} | |
}); | |
} | |
}; | |
}]); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html ng-app="myApp"> | |
<head> | |
<script src="//code.jquery.com/jquery-1.9.1.min.js"><\/script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"><\/script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="myController"> | |
<input type="text" ng-model="nospace" input-validation="restrictSpaces"> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">var app=angular.module("myApp", []); | |
app.controller("myController", function($scope){ | |
}); | |
app.directive('inputValidation', [ | |
function() { | |
return { | |
restrict : 'A', | |
require : 'ngModel', | |
link : function(scope, elem, attrs, ctrl) { | |
var pattern,flag=0,data=0; | |
elem.on('blur',function(e){ | |
switch(attrs.inputValidation) { | |
case "withTwoDigits": | |
modifyValues(); | |
break; | |
default: | |
break; | |
} | |
function modifyValues(){ | |
var a=$(e.currentTarget).val(); | |
if(a=="0.00"||a=='.00'){ | |
$(e.currentTarget).val(0); | |
} | |
if(a[0]=='.'&& typeof(a[1])=='undefined'){ | |
$(e.currentTarget).val(0); | |
} | |
else if(a[0]=='.'&& typeof(a[1])!='undefined'){ | |
$(e.currentTarget).val(0+a); | |
} | |
} | |
}); | |
elem.on('focusin',function(e){ | |
if(flag===0){ | |
flag=1; | |
data=$(e.currentTarget).val(); | |
} | |
else{ | |
} | |
}); | |
elem.on('focusout',function(){ | |
flag=0; | |
}); | |
elem.on('keyup', function(e) { | |
switch(attrs.inputValidation) { | |
case "restrictSpaces": | |
pattern = /^[a-zA-Z0-9]*$/; | |
pat1=/[^a-zA-Z0-9]/g; | |
break; | |
case "pwdCheck" : | |
pattern = /^[a-zA-Z0-9!@#%$^&*()]*$/; | |
pat1=/[ ]/g; | |
break; | |
case "onlyNumbers": | |
pattern=/^[0-9]*$/; | |
pat1=/[^0-9]/g; | |
break; | |
case "withTwoDigits": | |
pattern=/^[0-9]*(\.{1})?([0-9]{1,2})?$/; | |
pat1=/[^[]]/; | |
break; | |
default: | |
pattern = /^[^<>{}]*$/; | |
break; | |
} | |
if (!pattern.test($(e.currentTarget).val())) { | |
$(e.currentTarget).val(data); | |
} | |
else{ | |
data=$(e.currentTarget).val(); | |
} | |
}); | |
} | |
}; | |
}]);</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app=angular.module("myApp", []); | |
app.controller("myController", function($scope){ | |
}); | |
app.directive('inputValidation', [ | |
function() { | |
return { | |
restrict : 'A', | |
require : 'ngModel', | |
link : function(scope, elem, attrs, ctrl) { | |
var pattern,flag=0,data=0; | |
elem.on('blur',function(e){ | |
switch(attrs.inputValidation) { | |
case "withTwoDigits": | |
modifyValues(); | |
break; | |
default: | |
break; | |
} | |
function modifyValues(){ | |
var a=$(e.currentTarget).val(); | |
if(a=="0.00"||a=='.00'){ | |
$(e.currentTarget).val(0); | |
} | |
if(a[0]=='.'&& typeof(a[1])=='undefined'){ | |
$(e.currentTarget).val(0); | |
} | |
else if(a[0]=='.'&& typeof(a[1])!='undefined'){ | |
$(e.currentTarget).val(0+a); | |
} | |
} | |
}); | |
elem.on('focusin',function(e){ | |
if(flag===0){ | |
flag=1; | |
data=$(e.currentTarget).val(); | |
} | |
else{ | |
} | |
}); | |
elem.on('focusout',function(){ | |
flag=0; | |
}); | |
elem.on('keyup', function(e) { | |
switch(attrs.inputValidation) { | |
case "restrictSpaces": | |
pattern = /^[a-zA-Z0-9]*$/; | |
pat1=/[^a-zA-Z0-9]/g; | |
break; | |
case "pwdCheck" : | |
pattern = /^[a-zA-Z0-9!@#%$^&*()]*$/; | |
pat1=/[ ]/g; | |
break; | |
case "onlyNumbers": | |
pattern=/^[0-9]*$/; | |
pat1=/[^0-9]/g; | |
break; | |
case "withTwoDigits": | |
pattern=/^[0-9]*(\.{1})?([0-9]{1,2})?$/; | |
pat1=/[^[]]/; | |
break; | |
default: | |
pattern = /^[^<>{}]*$/; | |
break; | |
} | |
if (!pattern.test($(e.currentTarget).val())) { | |
$(e.currentTarget).val(data); | |
} | |
else{ | |
data=$(e.currentTarget).val(); | |
} | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment