Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Navigation
Latest Addons
AD Gallery 61
SyntaxHighlighte... 51
Newsletters v4.03 114
Facebook Like Box 132
Newsletters v4.02 60
Metro 169
Facebook Connect 173
Shoutbox Panel 128
Redactor for PHP... 107
MI Floating Side... 109
Facebook Login/R... 155
Avatar Studio v2.03 180
Relationship Sta... 98
Sexual Orientati... 116
Fisherman 144
Popular Addons
iTheme2 5808
Arise 5804
User Control v1.23 4623
Event Calendar 4052
Photowidget panel 3888
Radio-Theme red2... 3358
Highslide Gallery 3315
CSS/JavaScript D... 3234
Facebook Connect... 2988
Dynamic Menu 2895
Slideshow Lightb... 2725
L-AMANT 2659
Enigma 2637
2Dark 2608
Black 2580
Articles Hierarchy
Articles Home » PHP-Fusion v7 Tutorials » jQuery & PF v7 - how to... part 2
jQuery & PF v7 - how to... part 2
In previous part we're checked that PF password length is valid. Let make this checking more accurate - password strength. We need new function called getPasswordStrength() (I foud this somewhere in net ;), which returns integer value between 0 and 100. In this example strong password should return >= 70 points


?>
<script type='text/javascript'>
function getPasswordStrength(H){
var D=(H.length);
if (D<4) { D=0 }
if(D>5){D=5}
var F=H.replace(/[0-9]/g,"");
var G=(H.length-F.length);
if(G>3){G=3}
var A=H.replace(/\W/g,"");
var C=(H.length-A.length);
if(C>3){C=3}
var B=H.replace(/[A-Z]/g,"");
var I=(H.length-B.length);
if(I>3){I=3}
var E=((D*10)-20)+(G*10)+(C*15)+(I*10);
if(E<0){E=0}
if(E>100){E=100}
return E
}
var profile_errors = 0;
$(function(){
$("input[@type=password]").blur(function(){
profile_errors = 0;
$("#"+$(this).attr("name")+"_validate").remove();
if ($(this).val().length>0) {
if ($(this).val().length<6 || $(this).val().length>20) {
$(this).after("<div style='background:yellow;border:1px solid red;color:red;padding:2px' id='"+$(this).attr("name")+"_validate'>Password should contain between 6 and 20 chars...</div>");
profile_errors++;
} else if (getPasswordStrength($(this).val())<70) {
$(this).after("<div style='background:yellow;border:1px solid red;color:red;padding:2px' id='"+$(this).attr("name")+"_validate'>Your password isn't enough strong. Strong password should contain lower and upper case chars, numbers and special signs...</div>");
profile_errors++;
}
}
});
$("input[@name=update_profile]").bind("click", function(){
if (profile_errors>0) {
alert("Some of user fields contain errors\nPlease verify your data before update your profile.");
return false;
}
});
});
</script>
<?php


In above example for each INPUT fields of PASSWORD type we were checked length and password strength. If any field does not match those rules we're inform user about that.

Password things is now out of our minds ;) Now let validate email address. We need another function called isValidEmailAddress() (also found somewhere in net ;). At this moment we also need to change philosophy of errors checking, because we need to check also other fields than PASSWORD. jQuery selectors helps us again. Every DIV with error will contain profile_errors CSS class. Before profile update we will check the number of profile_errors class at page. If profile_errors class count will be different than 0 then we will display alert message about:


?>
<script type='text/javascript'>
function isValidEmailAddress(emailAddress) {
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);
return pattern.test(emailAddress);
}
function getPasswordStrength(H){
var D=(H.length);
if (D<4) { D=0 }
if(D>5){D=5}
var F=H.replace(/[0-9]/g,"");
var G=(H.length-F.length);
if(G>3){G=3}
var A=H.replace(/\W/g,"");
var C=(H.length-A.length);
if(C>3){C=3}
var B=H.replace(/[A-Z]/g,"");
var I=(H.length-B.length);
if(I>3){I=3}
var E=((D*10)-20)+(G*10)+(C*15)+(I*10);
if(E<0){E=0}
if(E>100){E=100}
return E
}
$(function(){
$("input[@type=password]").blur(function(){
$("#"+$(this).attr("name")+"_validate").remove();
if ($(this).val().length>0) {
if ($(this).val().length<6 || $(this).val().length>20) {
$(this).after("<div class='profile_errors' style='background:yellow;border:1px solid red;color:red;padding:2px' id='"+$(this).attr("name")+"_validate'>Password should contain between 6 and 20 chars...</div>");
} else if (getPasswordStrength($(this).val())<70) {
$(this).after("<div class='profile_errors' style='background:yellow;border:1px solid red;color:red;padding:2px' id='"+$(this).attr("name")+"_validate'>Your password isn't enough strong. Strong password should contain lower and upper case chars, numbers and special signs...</div>");
}
}
});
$("input[@name=user_email]").blur(function(){
$("#"+$(this).attr("name")+"_validate").remove();
if (!isValidEmailAddress($(this).val())) {
$(this).after("<div class='profile_errors' style='background:yellow;border:1px solid red;color:red;padding:2px' id='"+$(this).attr("name")+"_validate'>Entered email address looks as invalid...</div>");
}
});
$("input[@name=update_profile]").bind("click", function(){
if ($(".profile_errors").size()>0) {
alert("Some of user fields contain errors\nPlease verify your data before update your profile.");
return false;
}
});
});
</script>
<?php


Now we have compete user profile validator which chcecks main user fields of PF v7. Of course you can validate other fields but I leave it for you :)

In next article how to force JS enabled in browser...

PS1: please remember about jQuery 1.2.x and 1.3.x differences of attribute selectors!
PS2: thanks to Pieka from Polish PF Support for formatting this article!
Posted by Wooya on October 26 2009 15:12:47
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Official Home of PHP-Fusion uses cookies. Some may already have been set. Read more about our Cookies here.
Please click the button I Consent Cookies to hide this bar and accept our cookies. If you continue to use the site with no action taken, we'll assume that you consent our cookies anyway.
Cookiebar Panel byVenue
Shoutbox
You must login to post a message.

23-05-2013 14:30
OK, you're right. Stopping flooding... Smile

23-05-2013 14:26
IMHO, as for the locales I see such way: newbie came to the main (any) product site and could readily download/discuss main parts - core, locale, plugins. It means that site must have those files and forum topics.

23-05-2013 14:14
Lol, You are right Tyler...

23-05-2013 14:07
hmmm weird. A conversation in the shoutbox. I think I've been told not to do that.... As I've been told STOP

23-05-2013 13:51
Sorry, but it sounds like some bull$hit marketing. Everyone must use clouds, bootstrap, kickstarter etc. only because it is modern and fashionable. Why everybody think that such way absolutely better, safer and so on for everyone?

23-05-2013 07:21
Exactly, what Domi said, but the sooner one starts using Github, the better and safer for all.

23-05-2013 06:15
Thanks for clarifying this.

22-05-2013 23:45
Itīs nothing that have been set in stone. Just a tip. Since Github is new, not everyone know where it heads yet. You can still use the locales forum if you prefer.

22-05-2013 22:20
Wouldn't it be appropriate to inform the translators? You've got a list! Disappointed I have to learn about this through the shoutbox. Angry

22-05-2013 21:55
Keeping locales on GH makes it easier for everyone, you can update, maintain and publish them much faster and users don't have to search on Google, NSS sites or SourceForge (I'm sure many don't even know that locales can be found at SF)

Last Seens
Last Seen > Admins
[SA] Richard... 00:17:18
[A] PHPar 00:42:58
[A] JoiNNN 01:10:52
[A] Kamillo 02:42:04
[A] jikaka 04:31:17


Last Seen > Members
[M] B90 < 5 mins
[M] KasteR 00:11:53
[M] DeeoNe 00:29:54
[M] tomigames 00:33:47
[M] afoster 00:36:22