本文介绍了没有正则表达式的字母数字验证javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如果我运行,验证只能在符号/上工作,如果我输入除/ didnt工作之外的其他符号。我不使用正则表达式。循环就像停止工作一样。if i run, validation just can be work only on symbol "/", if I input the other symbol except / didnt working. I'm not use regex. loop like stop work.if(nama!==""){var i;var list = new Array ("/","!", "@", "#","$","%","%","^","&","*", "(",")","_","+","=","-","`","~",";","<", ">",".","?","[","]","{","}",",");var llength = list.length;for(i=0; i<llength;>{ if(nama.match(list[i])) { alert("Full Name must not contain any number and symbol"); return false; }}}推荐答案if(nama!==""){ var regex= /^[a-zA-Z]+ 这不是很简单! 注意: 1.你说你没有使用正则表达式但是.match()实际上与正则表达式匹配。Isn't that very simple !Note:1. You are saying you are not using regex but, .match() actually match against a regular expression. Quote: match()方法在字符串中搜索与正则表达式的匹配,并返回匹配项,作为Array对象。The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object. 参考: JavaScript字符串匹配()方法 [ ^ ] 2.您说要允许使用字母数字但是来自你的警告信息看起来你想只允许角色。 希望,它有帮助:)Reference: JavaScript String match() Method[^]2. You are saying you want to allow alphanumeric but from your alert message it looks like you want to allow only the characters.Hope, it helps :) 这篇关于没有正则表达式的字母数字验证javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-12 12:19