遇到问题
input框中输入全角空格,提交时,使用以下方法并没有被过滤,表单提交成功。
const removeSpace = function(str) {
// 去除空格
if (!str) {
return ''
} else {
return str.replace(/s/gi, '')
}
}
解决方法
const removeSpace = function(str) {
// 去除空格
if (!str) {
return ''
} else {
return str.replace(/(s*)|(s*$)/g, '')
}
}
扩展--去除字符串首尾的空格
const removeSpace = function(str) {
// 去除空格
if (!str) {
return ''
} else {
return str.replace(/(^s*)|(s*$)/g, '')
}
}