正则表达式练习
出生日期 年 月 日 ()表示一个整体
console.log('1909'.match('^19\\d{2}$'));
console.log('2024'.match('^20(([01][0-9])|(2[0-4]))$'));
//年
console.log('1909'.match('^(19\\d{2})|(20(([01][0-9])|(2[0-4])))$'));
// 月
console.log('12'.match('^(0[1-9])|(1[0-2])$'));
// 日
console.log('12'.match('^(0[1-9])|(1[0-9])|(2[0-9])|(3[0-1])$'));
密码 6~12位
console.log('12345asdf'.match('^[0-9A-z]{6,12}$'));
身份证号码
console.log('123456789012345678'.match('^\\d{17}[0-9xX]$'));
邮箱
console.log('12345as@sin.com'.match('^\\w+@\\w+\\.\\w+$'));// \\.代表点本身
001~999
console.log('999'.match('^(00[1-9])|(0[1-9][0-9])|([1-9][0-9][0-9])$'));
类class
1.静态特征—属性,
2.动态特征—方法/函数
class类的关键词
Person 类名 默认首字母大写
class Person{
// 构造函数
constructor(name:string,sex:string,age:number){
this.name=name
this.sex=sex
this.age=age
}
name:string
sex:string
age:number
// 方法
chi() {
console.log('吃饭');
}
he(){
console.log('喝水');
}
}
// console.log(lzh.name='六');//重新赋值
console.log(lzh.name);//单独打印
lzh.chi()
lzh.he()
对象 类的实例
创建对象 实例化对象
通过对象名。属性 进行访问
DevEco Studio
export 加上关键词后,类可以在其他文件中被引用
export class Student{
id:string
name:string
sex:string
age:number
constructor( id:string,name:string,sex:string,age:number) {
this.id=id
this.name=name
this.sex=sex
this.age=age
}
}
启动页面时,自动执行函数中的内容:aboutToAppear()
continue//跳出本次循环
验证 (值,规则,对应的组件,):
patt(val:string,reg:string):boolean{
if(val.match(reg)){
return true
}
return false
}
}
@state 对于数组对象,无法实时刷新
// 获取原来数据
let r:Reg=this.reg[i]
// 删除并添加
this.reg.splice(i,1,r)