Header Ads

AlphaNumerical Directives


AlphaNumerical Directives


This only allows the alphabets and numbers in the input box. use this directive to block other than alphabets, and numbers in this functionalities

Add the directives name inside the input field

<input type = "text" name="name" alphaNumericOnly >


Save these directives and name it as allowalphanumericOnly

  
   @HostListener('keyup'['$event']) onKeyUp(event) {
        let value = this. eleRef.nativeElement.value;
        value = this. functionCall(value);
       
        this. eleRef.nativeElement.value = value;
    }

   @HostListener('paste'['$event']) onPaste(event) {

        this. eleRef.nativeElement.value 
         this. functionCall(_.replace(this. eleRef.nativeElement.value/[^a-zA-Z0-9 ]/g''));
    }

    functionCall(value) {
       value = _.replace(value/^\s/g'');
       value = _.replace(value/[^a-zA-Z0-9 ]/g'');

       return value;
    }

Post a Comment

0 Comments