Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Form Validation
- * For mobile devices and Ipad
- * Or any device which doesn't support HTML5 form validation
- */
- /* Email Validation */
- function ValidateEmail(email) {
- var expr = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
- return expr.test(email);
- };
- $(document).ready(function(){
- $("#SMS_PhoneNumber").keydown(function (e) {
- if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
- (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) ||
- (e.keyCode >= 35 && e.keyCode <= 40)) {
- return;
- }
- if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
- e.preventDefault();
- }
- });
- $('#firstname').bind('keyup blur',function(){
- var node = $(this);
- node.val(node.val().replace(/[^a-zA-Z]/g,'') ); }
- );
- $("#SMS_PhoneNumber").change(function () {
- var mobile = $(this).val();
- if (mobile.length <= 9) {
- $(this).addClass("inputerror");
- } else if (mobile.length > 9) {
- $(this).removeClass("inputerror");
- }
- });
- });
- $(document).on("keyup", "input.inputerror", function(){
- $(this).removeClass("inputerror");
- });
- $(document).on("keyup", "#firstname", function(){
- $('#firstname').attr('placeholder', 'First Name').removeClass('placeholder-error');
- });
- $(document).on("keyup", "#email", function(){
- $('#email').attr('placeholder', 'Email').removeClass('placeholder-error');
- });
- var form = document.getElementById('form');
- form.noValidate = true;
- form.addEventListener('submit', function(event) {
- if (!event.target.checkValidity()) {
- event.preventDefault();
- var firstname = $('#firstname').val();
- var email = $('#email').val();
- if(firstname === ''){
- $('#firstname').addClass("inputerror");
- $('#firstname').attr('placeholder', 'First name is required').addClass('placeholder-error');
- }
- if(email === ''){
- $('#email').addClass("inputerror");
- $('#email').attr('placeholder', 'Email is required').addClass('placeholder-error');
- }
- if (!ValidateEmail($("#email").val())) {
- $('#email').addClass("inputerror");
- e.preventDefault();
- }
- }
- }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement