package com.zswc.creativity.utils

import android.content.Context
import android.content.Intent


/**
 *Created by shihuiyun
 *on 2020/10/16
 */
object VerifyUtils {


    /**
     * 验证输入的名字是否为“中文”或者是否包含“·”
     */
    fun isLegalName(name: String): Boolean {
        return if (name.contains("·") || name.contains("•")) {
            Regex("^[\\u4e00-\\u9fa5]+[·•][\\u4e00-\\u9fa5]+\$").matches(name)
        } else {
            Regex("^[\\u4e00-\\u9fa5]+\$").matches(name)
        }
    }


    /**
     * 验证输入的身份证号是否合法
     */
    fun isLegalId(id: String): Boolean {//
        return  Regex("(^\\d{15}\$)|(^\\d{17}([0-9]|X)\$)").matches(id.toUpperCase())
    }

    /**
     * 跳转 url地址
     */
    fun  isAndroidUrl(url:String,context: Context,flag:Boolean){
        try {
            if (url.contains("?")) {

                val i = Intent(context, Class.forName(StringUtils.getPureUrl(url)))
                val bundle = StringUtils.getUrlBundle(url)
                i.putExtras(bundle!!)
                if(flag) {
                    i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
                }
                context.startActivity(i)

            } else {

                val i = Intent(context, Class.forName(url))
                if(flag) {
                    i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
                }
                context.startActivity(i)


            }
        } catch (e: ClassNotFoundException) {
            e.printStackTrace();
        }
    }





}


