函数来确定一个字符串从另一个只包含字符 [英] Function to determine if a string contains characters only from another
本文介绍了函数来确定一个字符串从另一个只包含字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的HTML标签输入验证功能。我已经在特定的输入和含有允许的字符字符串的值的字符串。
I'm working on a validation function for html input tags. I've the string of the value of the particular input and the string containing the allowed characters.
var allowed = 'abcdefghijklmnopqrstuvwxyz";
var value = element.value;
我想编写一个函数,以确定是否值
仅包含允许的
字符串的字符。我在寻找一个直接的和简单的解决方案。
任何想法?
I'd like to write a function to determine if the value
contains character only from the allowed
string. I'm looking for a straight-forward and simple solution.
Any ideas?
推荐答案
是的,你可以使用正则表达式
Yes you can use regex
function alphanumeric(inputtxt)
{
var letters = /^[a-z]+$/;
//if you want upper and numbers too
//letters = /^[A-Za-z0-9]+$/;
//if you only want some letters
// letters = /^[azertyuiop]+$/;
if(inputtxt.value.match(letters))
{
alert('Your registration number have accepted : you can try another');
document.form1.text1.focus();
return true;
}
else
{
alert('Please input alphanumeric characters only');
return false;
}
}
这篇关于函数来确定一个字符串从另一个只包含字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文