Hey I have two questions.
One ive been trying to make my vars global but nothing working? How can I do this without affecting the functionality of the site? And Im trying to see if A user passwords & email match ive done this using two classes the same is there a better way in doing this?
Heres the HTML
PHP Code:
<form name='form'>
Username:<br>
<input type='text' name='user_reg' id='user_reg_input' placeholder='John,Nick,Terry,Mathew etc..'> <text id='user_check'> </text>
<br>
Password:<br>
<input type='password' name='pass_reg' id='pass_reg' class='reg' placeholder='Choose a strong Password'> <text id='result'> </text>
<br>
Comfirm Password:<br>
<input type='password' name='com_pass' id='com_pass' class='reg' placeholder='Comfirm Your Password'> <text id='com_pass_check'> Text> </text><br>
Email:<br>
<input type='email' name='email_reg' id='email_reg' class='email' placeholder='Enter A Vaild Email'> <text id='email_content'> Text </text><br>
Comfirm Email:<br>
<input type='email' name='com_email' id='email_com' class='email' placeholder='Comfirm Your Email'> <text id='com_content'> Text </text> <br>
<input type='submit' name='reg_procces' value='Sign Up'>
</form>
Heres the JQuery/Java Script
PHP Code:
var email_reg = $('#email_reg').val();
var email_con = $('#email_com').val();
$(document).ready(function() {
$('#title').keyup(function() {
var title = $('#title').val();
$.post('pages/get.php', { title: title}, function(data) {
$('#typing').html(data);
});
});
$('#user_check').load('check.php').show()
$('#user_reg_input').keyup(function() {
var user_reg = $('#user_reg_input').val();
$.post('check.php', {user_reg: form.user_reg.value },
function(result) {
$('#user_check').html(result).show();
});
});
$('#pass_reg').keyup(function(){
$('#result').html(checkStrength($('#pass_reg').val()))
})
function checkStrength(password){
//initial strength
var strength = 0
//if the password length is less than 6, return message.
if (password.length < 6) {
$('#result').removeClass()
$('#result').addClass('short')
return 'Too short'
}
//length is ok, lets continue.
//if length is 8 characters or more, increase strength value
if (password.length > 7) strength += 1
//if password contains both lower and uppercase characters, increase strength value
if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) strength += 1
//if it has numbers and characters, increase strength value
if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) strength += 1
//if it has one special character, increase strength value
if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1
//if it has two special characters, increase strength value
if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1
//now we have calculated strength value, we can return messages
//if value is less than 2
if (strength < 2 ) {
$('#result').removeClass()
$('#result').addClass('weak')
return 'Weak'
} else if (strength == 2 ) {
$('#result').removeClass()
$('#result').addClass('good')
return 'Good'
} else {
$('#result').removeClass()
$('#result').addClass('strong')
return 'Strong'
}
}
$('.reg').keyup(function()
{
var password = $('#pass_reg').val();
var com_pass = $('#com_pass').val();
if(password == com_pass) {
$('#com_pass_check').html('Success').val();
}
else {
if(password != com_pass)
$('#com_pass_check').html('Passwords Must Match').val();
}
{
if((jQuery.trim( password )).length==0)
$('#result').html('').val();
if((jQuery.trim( com_pass )).length==0)
$('#com_pass_check').html('').val();
}
});
$('#email_reg').keyup(function() {
var email_reg = $('#email_reg').val();
var email_con = $('#email_com').val();
var enteredEmailAddress=this.value;
var pattern = new RegExp(/^(("[\w-\s]+")|([w-]+(?:.[w-]+)*)|("[\w-\s]+")([w-]+(?:.[w-]+)*))(@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$)|(@[?((25[0-5].|2[0-4][0-9].|1[0-9]{2}.|[0-9]{1,2}.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}).){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})]?$)/i);
//white space here
if((jQuery.trim( email_reg )).length==0) {
$('#email_content').html('').val();
}
////vaild email
else if(email_reg) {
if(!pattern.test(enteredEmailAddress)) {
$('#email_content').html('Email Must Be Vaild').val();
}
if(pattern.test(enteredEmailAddress)) {
$('#email_content').html('Success').val();
}
//here
}
//post to php page here
});
$('.email').keyup(function() {
var email_reg = $('#email_reg').val();
var email_com = $('#email_com').val();
if(email_reg==email_com)
alert('Equal');
});
});
Since these codes are client side I can make it avliable to view since it is by the browser anyway.. I carn,t add Server side since this is A site project made to be public soon.
Thanks for the advice,
Spudster