[Jquery] regex | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 7

[Jquery] regex

Hey ! Help about jquery regex I've an input and I want to check if user write other than 0 and 1. If he write 2,3,4 etc... or 12 etc... and if the number contains other than 0 and 1 it write 'error' example : value of the input = '10001010111' -> true value of the input = '12' -> false : contains other number than 0 or 1

23rd Oct 2017, 10:34 AM
NoxFly
NoxFly - avatar
13 Respostas
+ 6
/^[01]*$/.test(input) // return true if only 0 and/or 1 replace the '*' with '+' to get false for empty string... > '*' means any times, '+' means one or more times > '^' at start means start of the string, '
#x27; at end means end of the string > '[]' define a class of possible char > regex.test(string) return true if pattern match
23rd Oct 2017, 1:21 PM
visph
visph - avatar
+ 17
ok
23rd Oct 2017, 2:35 PM
MattƩo
+ 17
ok
23rd Oct 2017, 2:35 PM
MattƩo
+ 15
Alors tas choisi qui pour le challenge ?
23rd Oct 2017, 2:26 PM
MattƩo
+ 14
Coucou
23rd Oct 2017, 1:55 PM
MattƩo
+ 5
Je ne sais plus de quelle autre fois tu parles... ( et j'men fous un peu beaucoup ;P ) Fais comme tu veux, mais sache que le principe initial de la marque pour la meilleure rĆ©ponse est de signaler aux lecteurs la rĆ©ponse la plus utile, pas nĆ©cessairement la premiĆØre donnĆ©e...
23rd Oct 2017, 1:32 PM
visph
visph - avatar
+ 5
ah ouai pas faux du tout :/
23rd Oct 2017, 1:36 PM
NoxFly
NoxFly - avatar
+ 4
So you want only jQuery no Javascript?
23rd Oct 2017, 10:40 AM
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬ - avatar
+ 4
So, mark it as best answer, maybe ^^
23rd Oct 2017, 1:26 PM
visph
visph - avatar
+ 4
yop
23rd Oct 2017, 2:15 PM
NoxFly
NoxFly - avatar
+ 3
attends je fini un truc et je te dis ;)
23rd Oct 2017, 2:26 PM
NoxFly
NoxFly - avatar
+ 2
thanks for all this explanations Visph ! :) really help me
23rd Oct 2017, 1:24 PM
NoxFly
NoxFly - avatar
+ 2
mdr honnĆŖtement je voudrais bien mais le mec avec un pseudo ultra long dont j'ai la flemme de recopier Ć  dit la rĆ©ponse avant, et si je te mets la meilleure rĆ©ponse, Ƨa lui enlĆØve du coup, et Ƨa ferait comme toi la derniĆØre fois quand tu t'es fĆ¢chĆ©. ... sauf que lĆ  ce serait lui.... alors jsp quoi faire
23rd Oct 2017, 1:28 PM
NoxFly
NoxFly - avatar