For the form validation in my AngularJS application, I am in need of regular expressions for two specific patterns with certain conditions.
Pattern 1:
The input box should only accept alphanumeric characters with no spaces. Additionally, users should be able to use special characters like ~!@#$-_
anywhere in the string, but none of the other characters such as (%, &, ^)
should be allowed. Leading and trailing whitespaces are also not permitted.
Examples:
ab@4_w : Valid
sd!tye123 : Valid
sd%tye123 : Invalid
sd*tye123 : Invalid
$scope.pattern1 = [\w~!@#\$-]+
Pattern 2: This pattern should only allow alphanumeric characters without spaces or underscores (_). No other characters are permitted, and leading/trailing whitespaces are not allowed.
Examples:
a4hgg5 : Valid
a4_6hy : Invalid
a@yb : Invalid
$scope.pattern2 = [\w]+
In order to meet the requirements mentioned above, adjustments need to be made to $scope.pattern1
and $scope.pattern2
.