ctpz Posted July 27, 2011 Report Share Posted July 27, 2011 У меня есть форма:<form action="/school/reg/newuser" name="reg" method="POST" id="regform"> <ul> <li> <label for="">Логин</label> <input class="text" type="text" maxlength="30" name="login" size="40" placeholder="логин" /> <span class="status">Error</span> </li> <li> <label for="">Пароль</label> <input class="text" type="password" maxlength="30" name="password" size="40" placeholder="пароль" /> <span class="status">Error</span> </li> <li style="margin-top: 15px;"> <label for="">Личные данные</label> <div style="float: left;"><label style="font-size: 15px;">имя</label><input class="text" type="text" maxlength="30" name="fname" size="17" placeholder="имя" /></div> <div style="display: inline-block;"><label style="clear: left; font-size: 15px;">фамилия</label><input class="text" type="text" maxlength="30" name="lname" size="18" placeholder="фамилия" /></div> </li> <li> <label for="">Почта</label> <input class="text" type="text" maxlength="30" name="email" size="40" placeholder="почта" /> <span class="status">Error</span> </li> </ul> </form><div align="center"><button id="submit" class="button">Подтвердить</button></div>И есть ее валидатор:if (document.reg.login.value == "" || document.reg.password.value == "" || document.reg.fname.value == "" || document.reg.lname.value == ""){ alert("Заполните все поля");}Как сделать, чтобы проверялось также поле e-mail по своему шаблону? Quote Link to comment Share on other sites More sharing options...
0 Int Posted July 28, 2011 Report Share Posted July 28, 2011 <input type="text" id="email">var mail=document.getElementById('email').value;if (!mail.match(/[a-z0-9][a-z0-9_\.-]+@[a-z0-9]([a-z0-9]*\.)+[a-z]{2,5}/i)) alert('плохая почта');Регулярку только что придумал, так что лучше свою напиши. Quote Link to comment Share on other sites More sharing options...
0 Nekromancer Posted July 28, 2011 Report Share Posted July 28, 2011 (edited) Когда то давно я писал так, вроде как "работает".if(key==='email'){ if(/[а-я]/i.test(value) || /\s/.test(value) || !/(^.*)?@([a-z_\-\.0-9]*)?\.([a-z\._\-0-9]+$)/i.test(value)){ alert('Неправильный электронный адрес!'); return; }}П.С. Если заметили в начале есть проверка на кириллицу, то есть адреса в кириллической доменной зоне не пройдут, если это проблема для вас, можете убрать первую проверку. Edited July 28, 2011 by Nekromancer Quote Link to comment Share on other sites More sharing options...
0 buddah Posted July 28, 2011 Report Share Posted July 28, 2011 Возможно будет полезно: http://livevalidation.com/examples 1 Quote Link to comment Share on other sites More sharing options...
0 ctpz Posted July 28, 2011 Author Report Share Posted July 28, 2011 (edited) buddah, спасибо. Именно что-то на подобии искал (это, но без фреймворка).Если у кого-то есть варианты, то не откажусь.Кстате, еще один вопрос:Я ни разу не вставлял в нативный js jquery код. Как я понимаю, что-то вот такое должно быть.if(document.reg.login.value == ""){$document.ready(function(){// jquery код});}Правильно ли я понимаю? Edited July 28, 2011 by ctpz Quote Link to comment Share on other sites More sharing options...
0 Veseloff Posted July 28, 2011 Report Share Posted July 28, 2011 buddah, спасибо. Именно что-то на подобии искал (это, но без фреймворка).Если у кого-то есть варианты, то не откажусь.Кстате, еще один вопрос:Я ни разу не вставлял в нативный js jquery код. Как я понимаю, что-то вот такое должно быть.if(document.reg.login.value == ""){$document.ready(function(){// jquery код});}Правильно ли я понимаю?Похоже, что неправильно. Чего добиться-то надо? Quote Link to comment Share on other sites More sharing options...
0 sigma77 Posted July 28, 2011 Report Share Posted July 28, 2011 if(document.reg.login.value == ""){$document.ready(function(){// jquery код});}Всё тоже самое, что и в просто jsif(document.reg.login.value == ""){ // jquery код} Quote Link to comment Share on other sites More sharing options...
0 Great Rash Posted July 28, 2011 Report Share Posted July 28, 2011 нативный js jquery кодО как завернул то! Quote Link to comment Share on other sites More sharing options...
0 ctpz Posted July 28, 2011 Author Report Share Posted July 28, 2011 В нативный js, jquery код. Ну забыл поставить запятую. Что тут такого? Quote Link to comment Share on other sites More sharing options...
0 Golgi Posted July 28, 2011 Report Share Posted July 28, 2011 ctpz, зачем было только тему создавать, я бы тебе показал. Quote Link to comment Share on other sites More sharing options...
0 ctpz Posted July 28, 2011 Author Report Share Posted July 28, 2011 Та ты предлагал jquery, а я считаю, что нативный js лучше использовать как основу, а при помощи ой потом интерфейс отделывать. Quote Link to comment Share on other sites More sharing options...
0 Golgi Posted July 28, 2011 Report Share Posted July 28, 2011 я уже сделал почти, можешь не напрягаться Quote Link to comment Share on other sites More sharing options...
0 ctpz Posted July 28, 2011 Author Report Share Posted July 28, 2011 Thanks. Я бы и сам сделал, но с мылом загвоздка получилась. Quote Link to comment Share on other sites More sharing options...
0 Int Posted July 28, 2011 Report Share Posted July 28, 2011 document.reg.login.valueА такой подход не слишком староват? Сейчас же через getEelement всё делают Quote Link to comment Share on other sites More sharing options...
0 ctpz Posted July 28, 2011 Author Report Share Posted July 28, 2011 if(document.getElementById('login') == ""){}Так? Я правильно понял? Quote Link to comment Share on other sites More sharing options...
0 Golgi Posted July 28, 2011 Report Share Posted July 28, 2011 ну value то забыл дописать Quote Link to comment Share on other sites More sharing options...
0 ctpz Posted July 28, 2011 Author Report Share Posted July 28, 2011 Ясно. Спасибо. Quote Link to comment Share on other sites More sharing options...
Question
ctpz
У меня есть форма:
И есть ее валидатор:
Как сделать, чтобы проверялось также поле e-mail по своему шаблону?
Link to comment
Share on other sites
16 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.