Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  121] [ 3]  / answers: 1 / hits: 42260  / 9 Years ago, wed, february 25, 2015, 12:00:00

here is my code and it's not working in my form.



<script type=text/javascript>
function valid(){
var pin_code=document.getElementById(pin);
var user_mobile=document.getElementById(phone);
var user_id=document.getElementById(email);
var pat1=/^([0-9](6,6)+$/;
var pattern=/^([0-9](10,10))+$/;
var filter=/^([a-z A-Z 0-9 _.-])+@(([a-z A-Z 0-9-])+.)+([a-z A-z 0-9]{3,3})+$/;

if (!filter.test(user_id.vlaue)) {
alert(Email is in www.gmail.com format);
user_id.focus();
return false;
}
if (!pattern.test(user_mobile.value)) {
alert(Phone nubmer is in 0123456789 format );
user_mobile.focus();
return false;
}
if (!pat1.test(pin_code.value)) {
alert(Pin code should be 6 digits );
pin_code.focus();
return false;
}
}
</script>


Here is the issue, when i submit the form whether i enter digits or characters in the mobile number or pin code it's accepting that value also. and when i am using these codes in partitions means like for email



<script type=text/javascript> 
function valid() {
var user_id=document.getElementById(email);
var filter=/^([a-z A-Z 0-9 _.-])+@(([a-z A-Z 0-9-])+.)+([a-z A-z 0-9 {3,3})+$/;
if(!filter.test(user_id.vlaue)) {
alert(Email is in www.gmail.com format);
user_id.focus();
return false;
}
}
</script>


in this code it's working properly but it's not working when i am using all the codes in one single form.



Please help me. Thank You.


More From » regex

 Answers
202

Just change pat1 and pattern to this:



var pat1=/^d{6}$/;
var pattern=/^d{10}$/;


Full working java-script as follows:



<script type=text/javascript>
function valid()
{
var pin_code=document.getElementById(pin);
var user_mobile=document.getElementById(phone);
var user_id=document.getElementById(email);
var pat1=/^d{6}$/;
var pattern=/^d{10}$/;
var filter=/^([a-z A-Z 0-9 _.-])+@(([a-z A-Z 0-9-])+.)+([a-z A-z 0-9]{3,3})+$/;
if(!filter.test(user_id.value))
{
alert(Email is in www.gmail.com format);
user_id.focus();
return false;
}
if(!pattern.test(user_mobile.value))
{
alert(Phone nubmer is in 0123456789 format );
user_mobile.focus();
return false;
}
if(!pat1.test(pin_code.value))
{
alert(Pin code should be 6 digits );
pin_code.focus();
return false;
}
}
</script>

[#67679] Monday, February 23, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
longd

Total Points: 616
Total Questions: 110
Total Answers: 101

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;