输入框手机号校验以及EditText的

// 失去焦点验证
et_phone.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
int index = detail_header_view_list
.indexOf(headerView);
clickHeader(index);
} else {
String phone = headerView.et_phone.getText().toString().trim();

setEditText(et_mobile, phone);
if (!Utils.isEmpty(phone)) {
checkMobile(c.CstGUID, phone,headerView.et_phone);
      }
    }
  }
});

/*********************************** 检测手机号**开始 *******************************************/

private void checkMobile(String cstId, String mobile,final EditText et_mobile) {
// 验证格式
if (!Validater.isMobileNumber(mobile)) {
String msg = "请输入正确手机号码!";
et_mobile.setError(msg);//此提示方法挺酷的
showConfirmDialog(msg);
errorMoblieMap.put(mobile, msg);
return;
}

// 判断超度进行截取
if (mobile.length() == 8) {
mobile11 = mobile.substring(0, 8);
} else if (mobile.length() == 10) {
mobile11 = mobile.substring(0, 10);
} else {
mobile11 = mobile.substring(0, 11);
}
if (passedMobileList.contains(mobile11)) {
return;
}

if (errorMoblieMap.containsKey(mobile11)) {
String msg = errorMoblieMap.get(mobile11);

/**
* 字符串截取
*/
String resultList[]=msg.split("。");//以分号截取
String phoneList[]=resultList[2].split(":");//截取手机号
final String phone=phoneList[1].split("O")[0].trim();//手机号
try {
prompt =resultList[0]+" \n"+"接待方式:"+phoneList[2]+" \n";
} catch (Exception e) {
prompt = resultList[0]+" \n";
}

et_mobile.setError(prompt);//设置点击后出现弹出框
showNoticeDialog(msg);
return;
}

final CheckMobileLogic cmLogic = new CheckMobileLogic() {
@Override
public void updateUIBySucess(ResponseBase result) {
dismissDialog();
if (result != null&& result.error.equals(Constants.ERROR_CODE_SUCCESS)) {
passedMobileList.add(mobile11);
if (errorMoblieMap.containsKey(mobile11)) {
errorMoblieMap.remove(mobile11);
}
} else {
dealFailMsgByDialog(ACTION_CHECK, "手机号码", result, false);
if (result != null
&& result.error
.equals(Constants.ERROR_CODE_FOR_SHOW)) {
errorMoblieMap.put(mobile11, result.msg);
et_mobile.setError(result.msg);
}
}
};

@Override
public void updateUIByError(VolleyError error) {
dismissDialog();
dealErrorMsgByDialogNotice(ACTION_CHECK, "手机号码", error);//返回信息错误时,通知上一个人(短信/电话)
if (error != null) {
ResponseBase result = parseError(error);
if (result != null&& result.error.equals(Constants.ERROR_CODE_FOR_SHOW)) {
errorMoblieMap.put(mobile11, result.msg);
/**
* 字符串截取
*/
String resultList[]=result.msg.split("。");//以分号截取
String phoneList[]=resultList[2].split(":");//截取手机号
final String phone=phoneList[1].split("O")[0].trim();//手机号
try {
prompt =resultList[0]+" \n"+"接待方式:"+phoneList[2]+" \n";
} catch (Exception e) {
prompt = resultList[0]+" \n";
}

et_mobile.setError(prompt);//设置点击后出现弹出框
}
}
};
};

showWaitDialog(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cmLogic.cancelRequest();
}
});
cmLogic.checkMobile(oppid, cstId, UserInfo.project.ProjGUID, mobile11);//去检查服务端是否相同
}

/**
* 检查客户手机号
* @author JieRain
*/
public class CheckMobileLogic {
private final String TAG_REQUEST="CheckMobile";

/**
* 检查客户手机号
*/
public void checkMobile(String oppId, String cstId, String pid , String mobile) {

NewcgListener listener= new NewcgListener() {
@Override
public void HandlerSuccess(String response) {
ResponseBase result=null;

try {
if(!response.isEmpty())
{
Gson g=new Gson();
result=g.fromJson(response, ResponseBase.class);
}
} catch (Exception e) {
Log.log(TAG_REQUEST, e);
}

updateUIBySucess(result);
}

@Override
public void HandlerError(VolleyError error)
{
updateUIByError(error);
}
};

CustomerRequest.CheckMobile(TAG_REQUEST,oppId, cstId, pid, mobile, listener);
}

public void cancelRequest(){
VersionRequest.cancelRequest(TAG_REQUEST);
}

public void updateUIBySucess(ResponseBase result){};
public void updateUIByError(VolleyError error){};
}

/**
* 验证客户手机号是否存在
* @param tag
* @param oppId 销售机会ID
* @param cstId 客户ID
* @param pid 明源系统项目id
* @param tel 手机号
* @param listener
*/
public static void CheckMobile(String tag, String oppId, String cstId, String pid, String tel, NewcgListener listener)
{
String url=String.format(CHECK_CUSTOMER_MOBILE_URL,pid,tel);
if(!Utils.isEmpty(oppId)){
url += "/oppid/" +oppId;
}
if(!Utils.isEmpty(cstId)){
url += "/cstid/" +cstId;
}
url += "/t/"+Utils.getCurrentTime();
NewcgStringRequest request =new NewcgStringRequest(Request.Method.GET,url,null,listener.SuccessListener(),listener.ErrorListener());
request.setTag(tag);
queue.add(request);
}

public class NewcgStringRequest extends NewcgRequest <String>{

public NewcgStringRequest(int method, String url, String requestBody, Response.Listener<String> listener,Response.ErrorListener errorListener) {
super(method,url,requestBody,listener,errorListener);
}

@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String parsed;
try {
parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
} catch (UnsupportedEncodingException e) {
parsed = new String(response.data);
}
Log.log("NewcgStringRequest-Volley-Response", parsed);
return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
}

/**
*
* <p>Title: NewcgRequest</p>
* <p>Description: 请求基类 </p>
* <p>Company: maxrocky</p>
* @author earl
* @date 2015-9-18
*/
public abstract class NewcgRequest <T> extends Request<T> {

public static final String Client_ID =Constants.Client_ID;
public static String VERSION;
public static final int SOCKET_TIMEOUT=30 * 1000;
/** Charset for request. */
private static final String PROTOCOL_CHARSET = Constants.PROTOCOL_CHARSET;
/** Content type for request. */
private static final String PROTOCOL_CONTENT_TYPE =String.format("application/json; charset=%s", PROTOCOL_CHARSET);
private final Response.Listener<T> mListener;
private final String mRequestBody;

private Map<String, String> headers;

public NewcgRequest(int method, String url,String requestBody, Response.Listener<T> listener,
Response.ErrorListener errorListener) {
super(method, url, errorListener);
mListener = listener;
mRequestBody = requestBody;
VERSION = Utils.getVersionName();
headers = new HashMap<String, String>();

CreateHeaders();
setRetryPolicy(new DefaultRetryPolicy(SOCKET_TIMEOUT, 0, 2f));
Log.log("NewcgRequest-Volley-Request", requestBody);
Log.log("NewcgRequest-Volley-URL", url);
}

private void CreateHeaders()//创建请求头
{
headers.put("clientid", Client_ID);
headers.put("version", VERSION);
if(Constants.IS_ZIP){
headers.put("Accept-Encoding", "gzip,deflate");
}
headers.put("accept","application/json");
if(!TextUtils.isEmpty(UserInfo.Access_Token)){
headers.put("access_token",UserInfo.Access_Token);
}
}

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers;
}

@Override
protected void deliverResponse(T response) {
mListener.onResponse(response);
}

@Override
public String getBodyContentType() {
return PROTOCOL_CONTENT_TYPE;
}

@Override
public byte[] getBody() {
try {
return mRequestBody == null ? null : mRequestBody.getBytes(PROTOCOL_CHARSET);
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s",
mRequestBody, PROTOCOL_CHARSET);
return null;
}
}

/**
* 本地验证手机号码格式 ^1[0-9]{10}(\\-[0-9]){0,1}$
*
* @param mobiles
* @return
*/
public static boolean isMobileNumber(String mobileNumber) {
Pattern p = null;
if (mobileNumber.length() == 8) {
p = Pattern.compile("^(9|6)[0-9]{7}$");//香港和澳门
} else if (mobileNumber.length() == 10) {
p = Pattern.compile("^09[0-9]{8}$");//台湾
} else{
p = Pattern.compile("^1[0-9]{10}(\\-[0-9]){0,1}$");
}
Matcher m = p.matcher(mobileNumber);
return m.matches();
}

时间: 2024-08-22 21:41:55

输入框手机号校验以及EditText的的相关文章

JavaWeb网上图书商城完整项目--day02-4.regist页面提交表单时对所有输入框进行校验

1.现在我们要将table表中的输入的参数全部提交到后台进行校验,我们提交我们是按照表单的形式提交,所以我们首先需要在table表外面添加一个表单 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core&

elementui表单输入框部分校验--判断

<template> <div> <div class="binding_main_nav"> <div class="binding_main_nav_div"> <div class="binding_main_nav_div_selection"></div> <span>绑定邮箱</span> </div> <div clas

Extjs表单输入框异步校验的插件实现

一.效果如图所示 特点: 1.异步后台校验不会对用户操作产生阻塞感: 2.可在用户停止输入后自动校验,避免频繁进行无谓的后台校验: 3.以插件方式实现,方便使用: 二.插件源码如下: /** * Created by jiawenjun on 2016/10/19. */ Ext.define('Ux.plugins.FieldAjaxVerify',{ extend: 'Ext.AbstractPlugin', alias: 'plugin.fieldajaxverify', buffer:5

NGUI的输入框的校验(input filed script)

一,我们制作一个输入框,右键添加Sprite ,给Sprite添加一个child的label,然后给Sprite添加一个box collider,接着添加input filed script,将label绑定到UIInput的label中,结果如下图: 二,看上图,我们发现UIInput有三个属性,Character Limit,Input Type和Validation来控制输入类型 Input Type:输入类型(standard)标准的,(AutoCorrect)自动修正,(Passwor

easyui-validatebox 使用,校验、鼠标移开onblur,onchange,setvalue,getvalue

<input type="text" class="easyui-validatebox" data-options="editable:true,novalidate:true,required:true" name="ProduceSrcTel" id="ProduceSrcTel" style="width: 120px;" />其中novalidate:true  这

android学习笔记(2)EditText控件的学习

对应若水老师的第五课 一,设置一个输入框 添加控件: <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="52dp" <!--本控件顶部距离上一个控件的距离--> /> 二,消除输入框的聚焦 方法一: <EditText android:layout_wi

【Android】EditText的特殊属性介绍

1.dayText3.setInputType(InputType.TYPE_NULL);  不让edittext按enter键后,弹出输入框 2.在使用EditText的XML 文件中加入一个属性: android:textCursorDrawable="@null" android:textCursorDrawable   这个属性是用来控制光标颜色的, "@null"   是作用是让光标颜色和text color一样 android:textCursorDra

js数据校验插件

//数据校验 /** *{type:"类型",notEmpty:true,regxp: reg,MaxLength: number,MinLength number,message: '错误提示信息'} * 校验类型 type:phone(手机号)/mail(邮箱)/mount(整数)/money(金额)/passwd(密码)/reg(正则验证)/notNull(不能为空) 必填 * 是否可为空 Emptable: true(true可为空,false不能为空:默认为false) *

常用输入框测试用例设计分享

普通输入框字段校验测试 1. 不输入,空内容 2. 输入1个字符 3. 若输入框有长度限制为N个字符,测试N-1个字符,N个字符,N+1个字符,N+N+...(超长)这几个边界值 4. 还需要测试下通过复制大于长度的值粘贴进去看是否能输入 5. 输入半角/全角空格 6. 输入半角/全角,大写/小写英文字符 7. 输入半角/全角数字 8. 输入简体中文字符(默认全角) 9. 输入繁体中文字符(默认全角) 10. 输入半角特殊字符:!@#¥%……&*() 11. 输入全角特殊字符:[email pr