Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
bad-frog5523yi think your regex is wrong.
regex 2 and regex 4: /^[6-9]/ instead of /[^6-9]/
instead of asking whether the first caracter is 6-9 you ask if string contains a caracter ^ or caracters 6-9 wherever in the string. -
bad-frog5523yalso, isnt there a way of doing that without regex?
like
if (string[0] > '5')
{
var msg = "valid"
}
(btw, im not a js guy. forcing me to use methods and even regex for such trivialities is what makes me hate oop) -
bad-frog5523y@Prem440 to clarify: im pretty sure about the regex, but like i stated, i dont really know JS.
also changing a caracter in your regexp is faster than rewriting the whole shebang:)
the latter is just an idea. dont know how JS treats caracters tho. you might have to pass said caracter through parseInt before you can do the comparison -
Did you just post this shit even after being warned not to? Please leave this platform.
-
iiii92263yRegexp is wrong. And you don't need it in the first place. Use your head instead of random stuff from SO
-
homie, devRant isn't for getting help with your code problems, that's what StackOverflow is for.
-
iiii92263y@sudo-woodo even stack overflow will tell him to get the fuck out with such beginner level questions.
Related Rants
I have JS code like this to phone num validation... But, it's showing as "valid" msg for the mobile num which i had entered is started with 0,1,2,3,4,5...
But, I want "Valid" msg for mobile num which is starting with 6-9 only.
(Remaing code & functionality are working correctly in/with HTML & CSS code)
Ex : 6012345987 --> valid
JS :
---
function checkPhoneNum()
{
var phone = document.getElementById("pNum").value
var phoneLen = phone.length
var regExp1 = /[0-9]/
var regExp2 = /[^6-9]/
var regExp4 = /[^0-9]/
if (phoneLen == 0)
{
var msg = ""
document.getElementById("phn-err").innerHTML = msg
}
else if (phone.match(regExp1) && phoneLen == 13)
{
var msg = "Valid"
document.getElementById("phn-err").innerHTML = msg
}
else if (phone.match(regExp4) || phone.match(regExp2))
{
var msg = "Invalid"
document.getElementById("phn-err").innerHTML = msg
}
}
question
js
html5
css frontend
css
html
css3
html css
fromtend
html & css
javascript
frond end