jQuery Validate, need to prevent free email addresses (e.g. Gmail, Hotmail)

前端 未结 3 729
抹茶落季
抹茶落季 2020-12-21 07:36

I need to add a custom validation rule (or set of rules) to prevent a whole list of email addresses from registering. This is already running server side, but we want to hav

3条回答
  •  猫巷女王i
    2020-12-21 08:14

    If you already have this running server-side, just make an AJAX request back to your server to reuse the same validation logic. (Your client code will make a XMLHttpRequest back to the server, the server's validation logic runs, and returns the status to the client - all without requiring the HTML page to reload. You've already indicated that you're using jQuery, so this should be easy.)

    As an added bonus, your server-side code could cache the check - so that when the server repeats the check (probably only a few seconds later) for verification without client-involvement (necessary for security, as anything sent by the client can't be trusted - think Firebug, etc.) - the server may not need to repeat the full work of its check. (This may be too trivial to optimize, without knowing exactly what your server-side validation includes. If it includes any external calls to web services, etc., it is probably worth caching.)

提交回复
热议问题