Search Posts

Category: regex

Regex-replace text when text contains more than one dot

I have to make a regex that replace text except numbers and only one dot Here is my regex:: var a = text.replace(/[^0-9,.]/g, ”); But it does not replace dot. I have to replace dots more than one. here is the code: <!DOCTYPE html> <html> <script src=””></script> <body> <div ng-app=”myApp” ng-controller=”myCtrl”> <input production-qty ID=”test” ng-model=”testmodel” type=”text” /> </div> <script> var app = angular.module(“myApp”, []); app.directive(‘productionQty’, function () { return { require: ‘ngModel’, link: function (scope, […]

angularjs ng-pattern regex for 4 digits and 2 decimal

I am trying to create a Regex for a number with maximum 4 digits and if the input has decimal it has to have 2 digits – .20 and not .1. tried: ng-pattern=”/^[0-9]+(.[0-9]{1,2})?$/” //fail for 666666, .10, .1 Examples for valid inputs: 100.10 100 3000.10 Example for invalid: 10000 //has more then 4 digits before decimal 100.1 //has only 1 digit after decimal .10 //has no digits before decimal Thanks for any help. Source: AngularJS

Special characters in ng-pattern

So I have two inputs in my html. The second input has an ng-pattern=”pw”, where pw is the scope variable bound to the first input’s ng-model. I’m using this for password validation. I want the user to verify the password in the first input. This works fine except when regular expression reserved characters are being used. Ex: input1: !123 input2: !123 the ng-pattern will match these input1: $123 input2: $123 the ng-pattern will not match […]