开发者

Confirm password and email field in spring MVC

For our project I've build a registration form with Spring MVC. However one of the requirements was that the user have to confirm her/his email and password. I created 2 fields, email and email (confirm) and password, password (confirm). When i want to check if email equals email (confirm) and password equals password (confirm). Is it necessary to add the confirm field to my model? I'm not sure if its a good idea开发者_开发知识库 to add the confirm field to my model since its not relevant information.

Maybe you got any ideas?


I think, that most convenient method would be to add these properties to your ViewModel, but ViewModel is not necessarily 100% must correspond to your model. For example, database table users doesn't have password_confirm column, also confirm password isn't used in your data entities (or Model), but in View (UI) you use this data field, so ViewModel has this property.


Sandar,

There is no need to provide any extra fields at Model or Controller, just create your fields at the View part only.

Create four input tags like :

<form.... onsubmit="return checkConfirmFields();>

<input type="text" name="email"/>
<input type="text" name="confirmEmail"/>
<input type="password" name="pass"/>
<input type="password" name="confirmPass"/>
<input type="submit" value="Register"/>

</form>

Now before submitting your form call one javascript function, for e.g. checkConfirmFields in above example and write simple logic to compare your email, password with confirm fields, and accordingly return true or false.

Hopefully you must have basic idea of javascript as you are using Spring MVC.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜