A newbie here. just wanted to ask what is the meaning of the code below.
if((control.value as string).indexOf(' ') >=0)
I was doing some self-study and I could not understand it. Appreciate if you give a hand to explain it at a very low level.
here the full code;
export class UsernameValidators {
static connotContainSpace( control: AbstractControl) : ValidationErrors | null {
// this is the part when the validation is stated
if((control.value as string).indexOf(' ') >=0)
return { cannotContainSpace: true }
return null;
}
I am trying to explain you using a simple example:
.indexOf(' ')will find the first index number for space substring incontrol.valuelike in our example first space is present in index number 4, which is greater than zero , then if statement will execute.