10 examples of 'angular validators number only' in JavaScript

Every line of 'angular validators number only' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
32function positiveNumberValidator(control: FormControl): any {
33 if (!control.value) return null;
34 const price = parseInt(control.value);
35 return price === null || typeof price === 'number' && price > 0
36 ? null : {positivenumber: true};
37}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

29positiveNumberValidator(control:FormControl):any{
30 if(!control.value){
31 return null;
32 }
33 let price = parseInt(control.value);
34
35 if(price>0){
36 return null;
37 }else{
38 return {positiveNumber:true};
39 }
40}
60function positiveIntegerValidator($elt) {
61 let value = $elt.val().trim().replace(/^0+(.+)/, '$1');
62 $elt.val(value);
63 if (!value) {
64 return;
65 }
66 if (/^[0-9]+$/.test(value)) {
67 // Check that we are in the positive range of a golang int64 max value, which is
68 // 9223372036854775807 minus a safety marge due to comparison rounding errors.
69 if (parseInt(value) > 9000000000000000000) {
70 return {msg: "Value out of bound."};
71 }
72 } else {
73 return {msg: "Value must be a positive integer."};
74 }
75}
14validate(control: AbstractControl): { [validator: string]: string } {
15 if (!control || !control.value) { // the [required] validator will check presence, not us
16 return null;
17 }
18 const expression = /^(\d+((\.|,)\d+)?)$/i;
19 const value = typeof control.value === 'string' ? control.value.trim() : control.value;
20 if (expression.test(value)) {
21 return null;
22 }
23 return {numeric: 'Please enter a valid number'};
24}
71formValidator(formGroup: FormGroup) {
72 return parseInt(formGroup.get('from').value, 10) < parseInt(formGroup.get('to').value, 10) ? null : {'mismatch': true};
73}
809static validateNumber (val) {
810 return Number(val);
811}
12function intGreaterThanZeroValidator(instance: DependencyObject, propd: DependencyProperty, value: any) {
13 if (typeof value !== "number")
14 return false;
15 return value > 0;
16}
8function validateNumber(num) {
9 num = (num + '').replace(/\s+|-/g, '');
10
11 if (!/^\d+$/.test(num)) {
12 return false;
13 }
14
15 var card = cardFromNumber(num);
16
17 if (card) {
18 var cardNumbers = A(card.length);
19
20 return ( cardNumbers.includes(num.length)) && (card.luhn === false || luhnCheck(num));
21 }
22
23 return false;
24}
26validate(c: AbstractControl): {[key: string]: any} {
27 return this.validator(c);
28}
149validateNumber: function validateNumber(name) {
150 var opts = arguments[1] === undefined ? {} : arguments[1];
151
152 if (util.type(this[name]) === "number") {
153 if (opts.nonnegative && this[name] < 0) {
154 this.addError(name, "must not be negative");
155 }
156
157 if (opts.maximum && this[name] > opts.maximum) {
158 this.addError(name, "may not be greater than " + opts.maximum);
159 }
160
161 if (opts.minimum && this[name] < opts.minimum) {
162 this.addError(name, "may not be less than " + opts.minimum);
163 }
164 } else if (!isBlank(this["" + name + "BeforeCoercion"])) {
165 this.addError(name, "is not a number");
166 }
167},

Related snippets