我有一个文本框,并且我想不带按钮单击该文本框不接受符号和大写字母。它仅接受字母数字值。但我不想检查按钮单击,例如:
@Controller
@RequestMapping("/Customer")
public class CustomerController {
//-------------------------------------//
@ModelAttribute("ma_CustomerTO")
public CustomerTO AM1(Model model) {
logger.debug(model.asMap()); //-----> does not print the model attributes from view???
CustomerTO customer=new CustomerTO();
customer.setCustName("Sheldon");
customer.setCustSpouse("Amy");
logger.debug(model.asMap());
return customer;
}
//-------------------------------------//
@RequestMapping("/SignupValidate.htm")
public ModelAndView HM1(Model model,@ModelAttribute("ma_CustomerTO") CustomerTO customer){
logger.debug(model.asMap());//-----> but this one prints
}
}
当用户开始输入内容时,我希望文本框不接受符号和大写字母。
任何想法或建议都会受到欢迎。
答案 0 :(得分:2)
使用jquery在文本框中仅接受字母数字字符串
$('#texboxID').on('keypress', function (event) {
var regex = new RegExp("^[a-z0-9]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
alert("Accept only small letter and numbers");
event.preventDefault();
return false;
}
});