Posts

Showing posts with the label Validation

Bootstrap 4 Form Input With Icon For Validation

Answer : Bootstrap 4 doesn't include icons (glyphicons are gone), and there are now just 2 validation states ( is-valid and is-invalid ) that control display of the valid-feedback and invalid-feedback text. With a little extra CSS, you can position an icon inside the input (to the right), and control its' display using is-valid or is-invalid on the form-control input. Use a font lib like fontawesome for the icons. I created a new feedback-icon class that you can add to the valid/invalid-feedback . .valid-feedback.feedback-icon, .invalid-feedback.feedback-icon { position: absolute; width: auto; bottom: 10px; right: 10px; margin-top: 0; } HTML <div class="form-group position-relative"> <label for="input2">Valid with icon</label> <input type="text" class="form-control is-valid" id="input2"> <div class="valid-feedback feedback-icon"> ...

Allow Only Numbers And Dot In Script

Answer : This is a great place to use regular expressions. By using a regular expression, you can replace all that code with just one line. You can use the following regex to validate your requirements: [0-9]*\.?[0-9]* In other words: zero or more numeric characters, followed by zero or one period(s), followed by zero or more numeric characters. You can replace your code with this: function validate(s) { var rgx = /^[0-9]*\.?[0-9]*$/; return s.match(rgx); } That code can replace your entire function! Note that you have to escape the period with a backslash (otherwise it stands for 'any character'). For more reading on using regular expressions with javascript, check this out: http://www.regular-expressions.info/javascript.html You can also test the above regex here: http://www.regular-expressions.info/javascriptexample.html Explanation of the regex used above: The brackets mean " any character inside these brackets ." Y...

Class-validator - Validate Array Of Objects

Answer : Add @Type(() => AuthParam) to your array and it should be working. Type decorator is required for nested objects(arrays). Your code becomes import { IsArray, ValidateNested, ArrayMinSize, ArrayMaxSize } from 'class-validator'; import { AuthParam } from './authParam.model'; import { Type } from 'class-transformer'; export class SignInModel { @IsArray() @ValidateNested({ each: true }) @ArrayMinSize(2) @ArrayMaxSize(2) @Type(() => AuthParam) authParameters: AuthParam[]; } Be careful if you are using any exception filter to modify the error reponse. Make sure you understand the structure of the class-validator errors. You can use the following: validator.arrayNotEmpty(array); // Checks if given array is not empty. validator.arrayMinSize(array, min); // Checks if array's length is at least `min` number. (https://github.com/typestack/class-validator#manual-validation) You may want to consider writing custom validator w...

Angular 4 Form Validators - MinLength & MaxLength Does Not Work On Field Type Number

Answer : Update 1 : phone: ['', [Validators.required, Validators.min(10000000000), Validators.max(999999999999)]], Used it like following and worked perfectly : phone: ['', [Validators.required, customValidationService.checkLimit(10000000000,999999999999)]], customValidationService : import { AbstractControl, ValidatorFn } from '@angular/forms'; export class customValidationService { static checkLimit(min: number, max: number): ValidatorFn { return (c: AbstractControl): { [key: string]: boolean } | null => { if (c.value && (isNaN(c.value) || c.value < min || c.value > max)) { return { 'range': true }; } return null; }; } } try this working sample code : component.html <div class="container"> <form [formGroup]="myForm" (ngFormSubmit)="registerUser(myForm.value)" novalidate> <div class="form-group" ...

Apex:pageMessages Includes The Entire Component Tree Path For A Apex:inputText With Required="true"

Answer : Try adding a label attribute to the inputText field - if there is no label, the error will display the whole tree, but with a label, it should just display the label + error message