Android代码片段:验证数据
生活随笔
收集整理的這篇文章主要介紹了
Android代码片段:验证数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
驗證郵箱
/*** check the email address is valid or not.** @param email pass email id in string* @return true when its valid otherwise false*/public static boolean isEmailIdValid(String email) {String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";CharSequence inputStr = email;Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);Matcher matcher = pattern.matcher(inputStr);if (matcher.matches())return true;elsereturn false;}驗證EditText是否為空
/*** check EditText is empty or not** @param edText pass EditText for check is empty or not* @return true or false*/public static boolean isEmptyEditText(EditText edText) {if (edText.getText().toString().trim().length() > 0)return false;elsereturn true;}判斷網(wǎng)絡(luò)
/*** check availability of Internet** @param context* @return true or false*/public static boolean isNetworkAvailable(Context context) {ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo netInfo = cm.getActiveNetworkInfo();if (netInfo != null && netInfo.isConnectedOrConnecting()) {return true;}return false;}日期選擇
/*** use to show datepicker** @param mContext* @param format of the date format* @param mTextView in which you have to set selected date*/public static void showDatePickerDialog(final Context mContext,final String format, final TextView mTextView) {new DatePickerDialog(mContext, new OnDateSetListener() {@Overridepublic void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {SimpleDateFormat dateFormatter = new SimpleDateFormat(format);dateTime.set(year, monthOfYear, dayOfMonth);mTextView.setText(dateFormatter.format(dateTime.getTime()).toString());}}, dateTime.get(Calendar.YEAR), dateTime.get(Calendar.MONTH),dateTime.get(Calendar.DAY_OF_MONTH)).show();}結(jié)束
總結(jié)
以上是生活随笔為你收集整理的Android代码片段:验证数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android代码片段:设备信息
- 下一篇: Ubuntu安装 AndroidStud