angularjs - angularjs中的提示框只允许字母数字字符
问题描述
我有一个 angularjs 函数,它为用户提供输入名称的提示框。我希望用户不要输入任何非字母数字值。对于提示框,如何限制输入?请找到以下向用户提供提示框的功能。
$scope.userInput = function(inputName)
{
var name = prompt("Please Enter your name", inputName);
};
解决方案
我使用了正则表达式,它成功了。请找到以下代码。
js
$scope.userInput = function(inputName)
{
var name = prompt("Please Enter your name", inputName);
var regPattern = /^[A-Za-z0-9]{2,}$/;
var regResult = regPattern.test(inputName);
if(regResult === true)
{
alert("correct name is given");
}
}
推荐阅读
- c# - Left MouseDoubleClick 事件的名称是什么?
- python - 在不正确的模式下创建 Django 数据库表
- math - 如何在没有伪影的情况下倾斜基于像素的径向渐变?
- azure - Databricks 中的 SAS 文件
- html - 如何为具有相同宽度的多个 div 水平对齐溢出椭圆?
- ssml - 如何将大型(超过 1500 个字符)SSML 语音文件用于带有 amazon polly 的 aws sumerian?
- ruby-on-rails - Ruby on Rails:编辑会话控制器创建操作以检查用户是否处于活动状态
- ruby-on-rails - Ralis 模块和调用静态方法
- sql - 无法删除系统生成的序列
- android - 如何从 Activity 更新导航标题中的 TextView?