[Jquery] regex | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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