// 判断字符串是否为空
function isEmptyString(str) {
// 如果字符串为 null 或 undefined 或 空字符串,则返回 true
return str == null || str === '';
}
// 示例使用
console.log(isEmptyString("")); // true
console.log(isEmptyString("hello")); // false
console.log(isEmptyString(null)); // true
console.log(isEmptyString(undefined)); // true
// 判断字符串是否只包含字母
function isAlpha(str) {
// 使用正则表达式判断字符串是否只包含字母
return /^[A-Za-z]+$/.test(str);
}
// 示例使用
console.log(isAlpha("hello")); // true
console.log(isAlpha("hello123")); // false
// 判断字符串是否为有效的电子邮件格式
function isValidEmail(email) {
// 使用正则表达式判断字符串是否符合电子邮件格式
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// 示例使用
console.log(isValidEmail("example@example.com")); // true
console.log(isValidEmail("invalid-email")); // false
上一篇:js 获取字符串中的数字
下一篇:js 判断是否字符串
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站