10 examples of 'angular validator number only' in JavaScript

Every line of 'angular validator 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}
71formValidator(formGroup: FormGroup) {
72 return parseInt(formGroup.get('from').value, 10) < parseInt(formGroup.get('to').value, 10) ? null : {'mismatch': true};
73}
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}
26validate(c: AbstractControl): {[key: string]: any} {
27 return this.validator(c);
28}
33constructor(private format: FormatService) {
34}
47private createValidator() {
48 this.validator = Validators.min(this.min);
49}
12function intGreaterThanZeroValidator(instance: DependencyObject, propd: DependencyProperty, value: any) {
13 if (typeof value !== "number")
14 return false;
15 return value > 0;
16}
17function NumberValidator(integer, parent) {
18 if (integer === void 0) { integer = false; }
19 if (parent === void 0) { parent = null; }
20 var _this = _super.call(this, parent) || this;
21 // attaching type validator
22 _this.addValidator('number', rules_1.number.number(), {});
23 if (integer)
24 _this.addValidator('integer', rules_1.number.integer(), {});
25 return _this;
26}

Related snippets