New course! Every coder should learn Generative AI!
Try a free lesson+ 2
What is "/[a-z]/" in js??
11 Answers
0
Sina Dont worry... Read they and if you dont understand something ask
+ 6
I don 't know much about javascript but this seems to work:
function a(){
var x = document.getElementById("in")
if(/[a-b]/g.exec(x.value) != null){
alert("you enterd s.th between a-b")
}
}
+ 3
Its an regex (regular expression) object that allow you to define a pattern (in this case an character from a to z lowercase)
https://www.w3schools.com/Jsref/jsref_obj_regexp.asp
+ 2
Thank you so much
+ 2
I saw the w3schools examples could you plz write for me more e.g??
+ 2
Can you write a code with both of them plz? if you could thanks
+ 2
Sina You have to be more clear on what you want get... If you want check if a string contain the pattern "s.th" (without quotes) you can do it with String.indexOf method also while with pattern you have to make your function "a" like:
function a(){
var x = document.getElementById("in").value
if( /s\.th/.test(x)){
alert("you enterd s.th between a-b")
}
}
Note that a String ITS DIFFERENT from a RegExpr:
"I am a string"
/I am a RegExpr/
Note start/end delimitator... Futhermore i have posted links because explain RegExpr its not simple above all in a comment... Please read these resources and post if you dont understand some concept
+ 1
I'm so sorry becuse I saw your links now
+ 1
How can I make s.th like this that works true
https://code.sololearn.com/WW92AUsdxu4z/?ref=app
0
# Below describe a pattern that atary with an lowecase alpha letter and follow least one alpha numeric (lowercase or uppercase) or underscore
/^[a-z][a-zA-Z0-9_]+/
# Below describe a pattern that must match or "i am" or "you are" followed by " good"
/(i am|you are) good/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
0
Sorry but what you dont understand? I have posted two links for make you read futhermore and while i can post other example i think that online resources make this much better than me