Regular expression for checking a field: a field must contain at least 2 alpha-numeric characters

I need to check the VARCHAR field. conditions: the field must contain at least 2 alpha-numeric characters

therefore, please, any of them gives a regular expression for the above conditions

I wrote the expression below, but it will check at least 2 letters are alphanumeric. and if my input has a value other than alphanumeric, it is not checked.

'^ [A-Za-Z0-9] {2} $'

Please, help.........

+3
source share
5 answers
[a-zA-Z0-9].*[a-zA-Z0-9]

Easy way: at least two alnum anywhere on the line.



( ) . - , OP, , ([a-zA-Z0-9].*?[a-zA-Z0-9]) . , :)

+6

:

[a-zA-Z0-9][^a-zA-Z0-9]*[a-zA-Z0-9]
+2

-? US ASCII . .

[[:alnum:]].*[[:alnum:]]

[^\W_].*[^\W_]

, \w , . double-negative : "not not-a-word-character not underscore".

+1

,

'\w.*\w'
0

[a-zA-Z0-9].*[a-zA-Z0-9] [a-zA-Z0-9].*?[a-zA-Z0-9].

- , , -, . . - , - ( , , , [a-zA-Z0-9], .).

( ):
, - , ( , Gumbo).
- , .

Test: http://jsbin.com/eletu/4
Compares 3 versions:

[a-zA-Z0-9].*?[a-zA-Z0-9]
[a-zA-Z0-9][^a-zA-Z0-9]*[a-zA-Z0-9]
[a-zA-Z0-9].*[a-zA-Z0-9]

Conclusion: no. As usual, you should check for typical data.

0
source

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


All Articles