验证用户输入 [英] Validation user inputs

查看:71
本文介绍了验证用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好编码员



我有一个问题我试图验证两个属性不相同当用户输入ei手机号码和传真号码时mvc 5?

hello coders

I have a question I am trying to validate two attributes not to be the same when a user enters them for e.i cellphone number and fax number in mvc 5?

推荐答案

嗨Simphiwe



首先要安装一个名为Foolproof mvc5的nuget根据你的MVC项目



右键单击你的项目>去管理Nuget包>

搜索foolproof.Mvc5现在我们中途完成。



转到模型视图(验证输入的类)ei



public string CellNumber {get;组; }

公共字符串NxtOfKinCellNumber {get;组; }



其中CellNumber是手机号码,FaxNumber是NxtOfKinCellNumber



在NextOfKinCellNumber下添加此语句



[NotEqualTo(CellNumber,ErrorMessage =请确保单元格编号与上述不同)]

公共字符串NxtOfKinCellNumber {get;组; }



希望这对你的问题很有帮助。

Happy Coding
Hi Simphiwe

First things first you have to install a nuget named Foolproof mvc5 under your MVC projects

Right click on your project >Go to manage Nuget Packages>
search for foolproof.Mvc5 now we half way to completion.

Go to your model view(class that you validation the inputs) for e.i

public string CellNumber { get; set; }
public string NxtOfKinCellNumber { get; set; }

where CellNumber is Cellphone Number and FaxNumber is NxtOfKinCellNumber

Under the NextOfKinCellNumber add this statement

[NotEqualTo(CellNumber, ErrorMessage=Please make sure cell number is not the same as the above)]
public string NxtOfKinCellNumber { get; set; }

Hope this is Helpful to your problem.
Happy Coding


这篇关于验证用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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