123456789101112131415161718192021222324252627282930313233343536373839 |
- import 'dart:typed_data';
- import 'package:flutter/services.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- class Utils {
- static bool isChinaPhoneLegal(String str) {
- return new RegExp('^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[8-9])|(147,145))\\d{8}\$').hasMatch(str);
- }
- static bool validateIDCard(String idCard) {
- final RegExp idCardRegExp =
- RegExp(r'^[1-9]\d{5}(18|19|20)\d{9}(\d|X|x)$');
- return idCardRegExp.hasMatch(idCard);
- }
- static bool isVerifyCode(String str) {
- if(str.length != 6)
- return false;
- return RegExp(r'^[0-9]+$').hasMatch(str);
- }
- // 保存数据
- static saveData(String key, String value) async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- await prefs.setString(key, value);
- // 其他数据类型可以使用prefs.setInt, prefs.setBool等
- }
- // 读取数据
- static Future<String> readData(key) async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- String data = prefs.getString(key) ?? '';
- return data;
- }
- }
|