Android 手机号,密码正则验证
来源:互联网 发布:人工智能的主要技术 编辑:程序博客网 时间:2024/05/13 17:45
Android 手机号,密码正则验证
*accont—->手机号 以1开头,10位结尾。哈哈,还有其他各种写法,我这里使用了简单的。
*password—->密码 6到18位的字母大小写及数字下划线。
参考菜鸟教程Java正则
public class ppp { public static boolean isMobileNO(String accont) { Pattern p = Pattern.compile("^1\\d{10}$"); Matcher m = p.matcher(username); return m.matches(); } public static boolean isPasswordNO(String password) { Pattern p = Pattern.compile("[0-9a-zA-Z_]{6,18}"); Matcher m = p.matcher(password); return m.matches(); }}
请求这里我是这样判断的
private void initView() { mBtnLogin = (TextView) findViewById(R.id.main_btn_login); user_username = (EditText) findViewById(R.id.username); user_password = (EditText) findViewById(R.id.password); mBtnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { account = user_username.getText().toString(); password = user_password.getText().toString(); if (TextUtils.isEmpty(account)) { Toast.makeText(getApplicationContext(),"请输入账号",Toast.LENGTH_SHORT).show(); return; } if (!ppp.isMobileNO(account)) { Toast.makeText(getApplicationContext(),"账号或密码错误",Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(password)) { Toast.makeText(getApplicationContext(),"请输入密码",Toast.LENGTH_SHORT).show(); return; } if (!ppp.isPasswordNO(password)) { user_password.setText(R.string.pwd_wrong); Toast.makeText(getApplicationContext(),"账号或密码错误",Toast.LENGTH_SHORT).show(); return; } // requestData(); } }); }
XML布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@mipmap/login_bg"> <LinearLayout android:layout_marginTop="55dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:layout_width="65dip" android:layout_height="65dip" android:layout_gravity="center_horizontal" android:src="@mipmap/oa" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:gravity="center" android:text="Excelled" android:textColor="#54ec97" android:textSize="24sp" android:layout_marginBottom="10dp"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="Fly away from here" android:textColor="#ffffff" android:textSize="16sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dip" android:orientation="vertical" android:padding="10dip" > <LinearLayout android:id="@+id/input_layout_name" android:layout_width="match_parent" android:layout_height="36dp" android:gravity="center_vertical" android:orientation="horizontal" android:background="@drawable/radius_drawable_bg"> <ImageView android:layout_marginLeft="8dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/login_paw_code" /> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:background="#00000000" android:hint="手机号" android:padding="5dip" android:maxLength="11" android:digits="1234567890" android:textSize="16sp" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:layout_marginBottom="5dip" android:layout_marginTop="15dip" android:background="#eeeeee" /> <LinearLayout android:layout_marginTop="10dp" android:background="@drawable/radius_drawable_bg" android:id="@+id/input_layout_psw" android:layout_width="match_parent" android:layout_height="36dp" android:gravity="center_vertical" android:orientation="horizontal" > <ImageView android:layout_marginLeft="8dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/login_paw_left" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:background="#00000000" android:hint="密码六位数以上字母组合" android:inputType="textPassword" android:padding="5dip" android:textSize="16sp" /> </LinearLayout> <TextView android:id="@+id/main_btn_login" android:layout_width="match_parent" android:layout_height="38dp" android:layout_marginTop="30dip" android:background="@drawable/button_radius30_lightblue" android:gravity="center" android:text="登录" android:textColor="@color/white" android:textSize="20sp" /> </LinearLayout> <RelativeLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center|right" android:text="忘记密码?" android:textSize="16sp" android:textColor="#fcfcfc" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_marginRight="15dp" android:layout_marginEnd="15dp" /> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text=".@2017上海xxxxx有限公司" android:textSize="12sp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout></LinearLayout>
阅读全文
0 0
- Android 手机号,密码正则验证
- Android手机号、密码、验证码正则表达式
- iOS正则表达式-验证密码身份证手机号
- 注册;;手机号和密码正则验证
- Android验证手机号、用户名正则表达式
- android 正则验证手机号是否正确
- Android验证手机号的正则表达式
- 用正则表达式验证邮箱、密码、QQ号、手机号、身份证号
- js正则表达式验证手机号,邮箱,QQ,密码
- iOS验证邮箱, 手机号, 密码, 账户名 --- 正则表达式
- iOS验证邮箱, 手机号, 密码, 账户名 --- 正则表达式
- ios使用常用正则表达式验证密码身份证手机号【转】
- ios使用常用正则表达式验证密码身份证手机号
- 手机号验证正则表达式
- 正则表达式手机号验证
- 手机号验证正则表达式
- 手机号验证正则表达式
- 手机号正则验证
- opengl入门
- 【UVA1331】关于最优三角剖分
- 单据开发时,怎样让字段是添加时间的值是当前的时间?
- 基于Spring、SpringMVC、MyBatis、Druid、Shrio构建web系统
- python 最大公约数与最小公倍数
- Android 手机号,密码正则验证
- apache对目录和地址的安全权限控制
- 用Java进行动态公式处理
- maven打包时去除不需要的jar包策略
- MySQL存储过程实例——实现查询数据表,有则更新无则插入
- IT连创业系列:说说苹果商店AppStore上架App应用前后遇到的那些神坑
- 11月第一次考试0
- 记录自学Web前端
- C++PrimerV5/Ch10/ex10.1-