如何验证“单行文本”字段只允许数字,逗号和空格 [英] How to Validate a "Single Line of Text" field to allow only numbers, commas and spaces

查看:102
本文介绍了如何验证“单行文本”字段只允许数字,逗号和空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用单行文本列供用户输入客户帐号,称为组号。 此群组编号列并不总是必需的(但我有一个列表验证公式,如果客户端状态的下拉列表
设置为"现有客户端"),则需要该列表验证公式。 

I'm using a Single Line of Text column for users to enter client account numbers, called Group Numbers.  This Group Numbers column is not always required (but I have a list validation formula in place that makes it required if the dropdown for the Client Status is set to "Existing Client"). 

对于此特定列表,我的组号列需要允许输入多个帐号,我希望用户能够用逗号和空格分隔它们。  我发现了一个列验证,只允许输入数字,
也允许它为空! 但它不会让我添加逗号和空格而不会出错。 

For this particular list, my Group Numbers column needs to allow multiple account numbers to be entered, and I'd like the user to be able to separate them by a comma and a space.  I found a column validation that allows only numbers to be entered and also allows it to be blank!  But it won't let me add commas and spaces without kicking out an error. 

我是SharePoint和公式的新手,我很难找到对我有用的东西。 我很感激你能给予的任何帮助! 谢谢!

I'm new to SharePoint and formulas, and I am struggling to find something that works for me.  I'd appreciate whatever help you can give!  Thanks!

推荐答案

您好,

请在PreSaveAction方法中使用正则表达式,在列表新项目表单中添加脚本:

Please use Regular Expression in PreSaveAction method like this, add the script in list new item form:

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript">
function PreSaveAction()
{
  var test=


(" input [title ='test']")。val();
var isNumeric = / ^ [0-9,\s] +
("input[title='test']").val(); var isNumeric = /^[0-9,\s]+


/ .test(test);
if(isNumeric)
{
return true;
}
其他
{
alert("请输入有效数字");
返回false;
}

}
< / script>
/.test(test); if(isNumeric) { return true; } else { alert("Please enter a valid number"); return false; } } </script>

结果:

英文字符无效:

1_2无效:

1.2无效:

1,2,3有效:




谢谢

最好的问候


这篇关于如何验证“单行文本”字段只允许数字,逗号和空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆