【发布时间】:2019-05-27 14:36:06
【问题描述】:
我想为我的语句设置一些索引并检查它是否找到我找到了这个方法 charAt 但它只适用于字符串,所以如何用数字处理这些
if (mobileNumber) {
let j = mobileNumber.charAt(2);
let w = mobileNumber.charAt(0);
alert("@", w, j)
if (j === 9) { //Not work quz it's a number
alert("FoundJ", j)
return;
} else if (w === 6) { //Not work quz it's a number
alert("FoundW", w)
return
} else{
alert("sorry, App does not work in your city right now")
return
}
更新
现在我处理索引但我对它们有一些问题这是我的声明 如果我写下数字并且它包含 9 || 6 in the (2)index 我在调用函数时看到了警报我不知道为什么?
let j = mobileNumber.toString().charAt(2);
if (mobileNumber.length <= 0) {
this.setState(
Object.assign(validations, {
mobileNumberValid: "• Please, write your Mobile Number"
})
);
return;
} else if (mobileNumber.length < 10) {
this.setState(
Object.assign(validations, {
mobileNumberValid:
"• Your Mobile Number must be exactly 10 characters!"
})
);
return;
} else if (regNumber.test(mobileNumber) === false) {
this.setState(
Object.assign(validations, {
mobileNumberValid: "• Please, Your mobile must be a number"
})
);
return;
}
else if (j != 9 || j != 6) { // i think the issue with **OR**
alert("sorry not work in your city yet!")
return;
}
else {
this.setState(
Object.assign(validations, {
mobileNumberValid: ""
})
);
}
【问题讨论】:
-
j === "9"? ... -
对不起,再检查一下
-
要么 j === '9' 要么 parseInt(j, 10) === 9 与 w 相同
-
很遗憾,我不太了解你
标签: javascript reactjs react-native ecmascript-6 numbers