Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 验证字符串中的数字和字母_String_Integer_Character_Validation - Fatal编程技术网

String 验证字符串中的数字和字母

String 验证字符串中的数字和字母,string,integer,character,validation,String,Integer,Character,Validation,我需要输入一个基本上是会员编号的字符串 它必须在开头包含两个字母,后跟四个数字 例如,AA1111或AB1234 如何验证前两位是字母,后四位是整数 在javaScripts中: function validate() { var input = document.getElementById("Text1").value; var re = new RegExp(/^[a-zA-Z]{2}[0-9]{4}$/); if (re.test(input)) {

我需要输入一个基本上是会员编号的字符串

它必须在开头包含两个字母,后跟四个数字

例如,
AA1111
AB1234

如何验证前两位是字母,后四位是整数

在javaScripts中:

function validate() 
{
    var input = document.getElementById("Text1").value;
    var re = new RegExp(/^[a-zA-Z]{2}[0-9]{4}$/);
    if (re.test(input)) 
    {
        alert("true");
    }
    else 
    {
        alert("false");
    }        
}

若我们拆分正则表达式,它将在开始和结束时验证输入字符串

^[a-zA-Z]{2}-----------------------------------------[0-9]{4}$
前两个字符必须是字母

^         =*from start*  
[a-zA-Z]  =*lower and upper case alpha*  
{2}       =*Exactly two character*  
最后四个字符必须是数字

[0-9]     =*digits*  
{4}       =*exactly four charater*  
$         =*at end*  

什么类型的用户界面?你试过什么?给我们看一些代码。即使没有regexp等非常基本的语言功能,这也很简单。旁注:数字是数字而不是字母。你的编程语言、框架、库等是什么?我的错。这是java,我正在使用Eclipse。
[0-9]     =*digits*  
{4}       =*exactly four charater*  
$         =*at end*