admin管理员组文章数量:1414605
I want a regex for alphanumeric characters in angularJS, I've tried some regex like "(\d[a-z])" but they allow me to enter only number as well as only alphabets. But I want a regex which won't allow me to enter them.
Example: 121232, abchfe, abd()*, 42232^5$ are some example of invalid input. 12fUgdf, dGgs1s23 are some valid inputs.
I want a regex for alphanumeric characters in angularJS, I've tried some regex like "(\d[a-z])" but they allow me to enter only number as well as only alphabets. But I want a regex which won't allow me to enter them.
Example: 121232, abchfe, abd()*, 42232^5$ are some example of invalid input. 12fUgdf, dGgs1s23 are some valid inputs.
Share Improve this question asked Jul 1, 2016 at 6:09 Ruchi yadavRuchi yadav 2433 silver badges16 bronze badges 3- Take a look stackoverflow./questions/388996/… – Pravesh Khatri Commented Jul 1, 2016 at 6:13
- Similar questions asked here stackoverflow./questions/18692187/… – S. Divya Commented Jul 1, 2016 at 6:17
- You want a regex that allows only digits and letters, and requires at least one of each? – nnnnnn Commented Jul 1, 2016 at 6:23
4 Answers
Reset to default 2This one requires atleast one of each (a-z, A-Z and 0-9):
^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])([a-zA-Z0-9]+)$
You can try this one. this expression satisfied at least one number and one character and no other special characters
^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$
in angular can test like:
$scope.str = '12fUgdf';
var pattern = new RegExp('^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$');
$scope.testResult = pattern.test($scope.str);
PLUNKER DEMO
If you wanted to return a replaced result, then this would work:
var a = 'Test123*** TEST';
var b = a.replace(/[^a-z0-9]/gi,'');
console.log(b);
This would return:
Test123TEST
OR
/^([a-zA-Z0-9 _-]+)$/
the above regex allows spaces in side a string and restrict special characters.It Only allows a-z, A-Z, 0-9, Space, Underscore and dash.
try this one : ^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]+$
dGgs1s23-valid
12fUgdf-valid,
121232-invalid,
abchfe-in valid,
abd()*- invalid,
42232^5$- invalid
本文标签: javascriptRegular expression for alphanumeric in AngularjsStack Overflow
版权声明:本文标题:javascript - Regular expression for alphanumeric in Angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745193391a2647021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论