Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js 判断字符串

作者:开阔蓝天uだ   发布日期:2025-09-13   浏览:67

// 判断字符串是否为空
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 判断是否字符串

大家都在看

js 数组对象排序

js 数组删掉第一个值

js fill

js 数组连接

js json数组

js 数组复制

js 复制数组

js 数组拷贝

js 对象转数组

js 深拷贝数组

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站