Angularjs regex

In my Angularjs application, I need to have a regex for two patterns to validate the form with the following condition.

Sample 1:

The input field must take an alphanumeric value without a space, and it must also allow the user to use type characters ~!@#$-_anywhere on the line, except that these characters, except for other characters, must be resolved as (%, &, ^ etc). It should also not allow for leading / closing spaces.

Examples:

 ab@4_w    :  valid
 sd!tye123  : valid
 sd%tye123  :  Invalid
 sd*tye123  :  Invalid

$ scope.pattern1 = [\ w ~! @ # \ $ -] +

Sample 2: Only an alphanumeric number must be allowed without a space and other characters, including (_). It should also not allow for leading / closing spaces.

Examples:

  a4hgg5  : Valid
  a4_6hy   : Invalid
  a@yb    : invalid

$ scope.pattern2 = [\ w] +

$scope.pattern1 $scope.pattern2 , .

+4
2

/ .

ng-trim="false" input.

- , ~!@#$-_ , , (%, &, ^ ..).

, , , , :

^[\w~!@#$-]+$

\w [a-zA-Z0-9_].

. , ^ $, : "[\\w~!@#$-]+".

- , (_).

: ^[a-zA-Z]+$. , , .

+1

Try

^[\w~!@#\$-]+$

  • ^
  • [\w~!@#\$-]+ , ( $ \$)
  • $

Regex101. , , * + . , \w i, , .

+1

Source: https://habr.com/ru/post/1660657/


All Articles