Javascript RegEx特殊字符

时间:2018-10-11 03:12:05

标签: javascript regex javascript-events

嗨,我的RegEx遇到问题,我不知道在哪里可以输入特殊字符代码以寻求帮助。

此功能用于验证字符,例如电子邮件内容与长度。但是当我输入一些特殊字符时,它不起作用。

<script type="text/javascript">




        function isEmpty(str){
            return (!str || 0 === str.length);
        }


            //alert(isEmpty(emailString1));
        function processString() 
        {
            var emailString1 = document.getElementById("txtArea1").value;
            var emailString2 = document.getElementById("txtArea2").value;
            var regex = new RegExp(emailString1,'gi');
            var count = (emailString2.match(regex) || []).length;

                    if (count == 1){
                        document.getElementById('EmailVal').innerHTML = "True";
                        document.getElementById('statusLog').innerHTML = "Validated and match";
                        document.getElementById('statusLog').style.color = "#009900"
                    } else {

                        document.getElementById('EmailVal').innerHTML = "False";
                        document.getElementById('statusLog').innerHTML = "Validated and match";
                        document.getElementById('statusLog').style.color = "#cc0000"
                    };

        }


</script>
<label id="EmailVal" style="width: 250px">Email Validation </label>
<br></br>
<label id="statusLog">Status</label>
<br> </br>
<input type="button" value="Process String" onClick="processString()" style="width: 250px"; />
<br> </br>





<div class="flex-container">
  <div class="box">
    <textarea id="txtArea1" rows="4" cols="30" style="width: 450px; height: 450px"; ></textarea>
  </div>
  <div class="box">
    <textarea class="float_rigth" id="txtArea2" rows="4" cols="30" style="width: 450px; height: 450px"; ></textarea>
  </div>
</div>

0 个答案:

没有答案