Im trying to confirm if the password strength is strong or weak and is the password is strong and when I submit it should have alert message like "You Have Strong Password" and when its weak "Invalid Password"
This is what I am now.
function checkPasswordStrength() {
var passwordStrength = false;
var number = /([0-9])/;
var alphabets = /([a-zA-Z])/;
var special_characters = /([~,!,#,#,$,%,^,&,*,-,_,+,=,?,>,<])/;
if ($('#password').val().length < 8) {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('weak-password');
$('#password-strength-status').html("Weak (should be atleast 8 characters.)");
} else {
if ($('#password').val().match(number) && $('#password').val().match(alphabets) && $('#password').val().match(special_characters)) {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('strong-password');
$('#password-strength-status').html("Strong");
return passwordStrength = true;
} else {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('medium-password');
$('#password-strength-status').html("Medium (should include alphabets, numbers and special characters.)");
}
}
}
$('#btn-submit').click(function () {
if (passwordStrength == false) {
alert("INVALID PASSWORD");
} else {
alert("You have Strong PASSWORD");
}
</script>
its for Educational Purpose only im just starting jquery..
thank you in advance..
You need to call the function instead of just checking your variable. So rather do
$('#btn-submit').click(function () {
if (checkPasswordStrength() === false) {
instead of
$('#btn-submit').click(function () {
if (passwordStrength == false) {
Then, instead of return passwordStrength = true; you should do just passwordStrength = true and add a return passwordStrength to the very end of your function so it will return either false or true.
It looks like the variable scope is incorrect. var passwordStrength should be put outside of the checkPasswordStrength function.
var passwordStrength
function checkPasswordStrength() {
....
Related
I'm using AngularJS ver. 1.2.15 on my project. And, I have a select element on one of my views as per below:
<select class="select-white form-control form-select" id="cat2_{{feed.id}}" ng-model="feed.operationstatusid" ng-change="updateCategoryAndStatus(feed, true)"></select>
And, I'm feeding this element like this:
function SetCategory2(cat1Id, feed) {
var feedId = feed.id;
var fromRuleOpStatusId = -1;
$('#cat2_' + feedId).find('option').remove();
if (cat1Id > -1) {
$('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));
$.each($scope.category2, function (index, cat2Item) {
$('#cat2_' + feedId).append($('<option></option>').text(cat2Item.statusdescription).val(cat2Item.id));
});
var isselected = false;
$.each($scope.category2, function (index, cat2Item) {
if (feed.operationstatusid == cat2Item.id) {
$('#cat2_' + feedId).val(cat2Item.id);
fromRuleOpStatusId = -1;
isselected = true;
}
else {
var feedStr = "";
if (feed.title != undefined && feed.title != null) {
feedStr = feed.title.toLowerCase();
}
if ($scope.catTitleRulesTwo) {
$.each($scope.catTitleRulesTwo, function (r_index, r_item) {
if (cat2Item.id == r_item.titleCode && !isselected) {
if (feedStr != undefined && feedStr != null && r_item != undefined && r_item != null) {
String.prototype.contains = function (str) { return this.toLowerCase().indexOf(str) !== -1; };
var text = feedStr;
if (eval(r_item.ruleexpression)) {
$('#cat2_' + feedId).val(cat2Item.id);
fromRuleOpStatusId = cat2Item.id;
isselected = true;
}
}
}
});
}
}
});
if (fromRuleOpStatusId != -1) {
feed.operationstatusid = fromRuleOpStatusId;
}
}
else {
$('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));
}
}
I am aware of the facts about eval function, but the project I'm working on is quite old, so does the code. Anyway, this is about business logic and quite irrelevant with the thing I'm going to ask (or so I was thinking).
As you can see I'm appending all the options before I set the value of the selectbox with using .val(...). I have also checked that values do match along with the data types. But, when I observe this function step by step, I saw that selected value does show up without flaw. After the code finish with my above mentioned function (SetCategory2), code goes through on of the function located on AngularJS file, named xhr.onreadystatechange. It's not a long function, so I'm sharing it also on below.
xhr.onreadystatechange = function() {
if (xhr && xhr.readyState == 4) {
var responseHeaders = null,
response = null;
if(status !== ABORTED) {
responseHeaders = xhr.getAllResponseHeaders();
response = ('response' in xhr) ? xhr.response : xhr.responseText;
}
completeRequest(callback,
status || xhr.status,
response,
responseHeaders);
}
};
After the code released from this function, respective selectbox's value is pointed at the empty option.
I have run into topics which talks about this behaviour might due to invalid option-value match, but as I described above, I append all my options before deciding the value. So, I can't figure out what I'm missing.
Thank you in advance.
Hello everyone)) I have problem with moving value inside th function, please help me
First I have field "allValid" - has taken boolean value "true".
Next I did 3 checking breakpoints in script where this field must change boolean value on "false".
But whatever i do allValid always has "true". I cant understand what am I doing wrong.
function ButtonClickAction(){
let allValid = true;
var UserInfo = {};
UserInfo.zLOGIN = document.getElementById("LOGIN").value;
UserInfo.zSSCC = document.getElementById("SSCC").value;
UserInfo.zPLACE = document.getElementById("PLACE").value;
var toValidate = {
LOGIN: "LOGIN REQUIRED",
SSCC: "SSCC REQUIRED",
PLACE: "PLACE REQUIRED"
}
var idKeys = Object.keys(toValidate);
//first checking
idKeys.forEach(function(id){
isValid = checkIfValid(id,toValidate[id]);
allValid = isValid;
});
//second checking
google.script.run.withSuccessHandler(onLOGIN).searchLogins(UserInfo);
function onLOGIN(findLogin) {
if (!findLogin) {
alert("LOGIN NOT EXIST");
allValid = false;
}
}
//thirdchecking
console.log(allValid);
google.script.run.withSuccessHandler(onSSCC).searchSSCC(UserInfo);
function onSSCC(findSSCC) {
if (!findSSCC) {
alert("SSCC NOT EXIST");
allValid = false;
}
}
//finish result
if (!allValid){
alert("YOU HAVE NOTHING");
}
else {
addRecord(idElem);
}
}
function checkIfValid(elId, message){
var isValid = document.getElementById(elId).checkValidity();
if(!isValid){
alert(message);
return false;
}
return true;
}
At the end of the function "ButtonClickAction" I have "finish result", but it works wrong because allValid has always "true". Help!
(sorry for bad English, it's my non-native language, I try explain correctly)
... and some server code:
var url = "https://docs.google.com/spreadsheets/d/1s8l-8N8dI-GGJi_mmYs2f_88VBcnzWfv3YHgk1HvIh0/edit?usp=sharing";
var sprSRCH = SpreadsheetApp.openByUrl(url);
let sheetSRCHSSCC = sprSRCH.getSheetByName("PUTAWAY_TO");
let sheetTSD = sprSRCH.getSheetByName("ПРИВЯЗКА МЕСТ");
function searchLogins(UserInfo){
let sheetSRCHLGN = sprSRCH.getSheetByName("ЛОГИНЫ");
let findingRLGN = sheetSRCHLGN.getRange("A:A").getValues();
let valToFind = UserInfo.zLOGIN;
for (let i = 0; i < findingRLGN.length; i++){
if(findingRLGN[i].indexOf(valToFind)!==-1){
return true;
}
};
return false;
}
function searchSSCC(UserInfo){
let findingRSSCC = sheetSRCHSSCC.getRange("M:M").getValues();
let valToFind = UserInfo.zSSCС;
for (let i = 0; i < findingRSSCC.length; i++){
if(findingRSSCC[i].indexOf(valToFind)!==-1){
return true;
break;
}
};
indx=2;
return false;
}
I'm trying to validate the value in my name element and email address element.
but the below code is not providing the proper validation and my code is still jumping to my php file with wrongs inputs in it.
can anybody please provide me some guidance on this?
var letters = /^[A-Za-z]+$/;
var mailformat = ^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})+$;
if( document.addform.First_name.value.match(letters)) {
return true;
}
else {
alert( "Username must have alphabet characters only" );
document.addform.First_name.focus() ;
return false;
}
if( document.addform.email.value.match(mailformat) ) {
return true;
}
else {
alert( "You have entered an invalid email address!" );
document.addform.email.focus() ;
return false;
}
You need to return true if both conditions are met, not just one of them.
function validateFormInput () {
let yourUsernameRegEx = new RegExp(...);
let yourMailRegEx = new RegExp(...);
if (!document.addform.First_name.value.match(yourUsernameRegEx)) {
// Other code here (alerts, popups, etc.) ...
return false;
}
if (!document.addform.email.value.match(yourMailRegEx)) {
// Other code here (alerts, popups, etc.) ...
return false;
}
return true;
}
how can I clean up this code. here is my function in my controller. I am using this to control 3 different custom made drop down lists in my html. I want when you click out of them, they close. I wish I didn't need to give them each their own variable for ng-show, but I think I do because if ng-show is true for one then they would all show together. Also is it wrong to put all this in a controller rather than a directive or factory or something - besides for cleaning up the function itself.
$scope.toggle = function (option,type) {
if (option == 'subdiv') {
$scope.notMain = true;
if ($scope.notMain) {
if (type == 'item') {
$scope.showItemOptions = true;
$scope.showOptions = false;
$scope.showOrderOptions = false;
}
else if (type == 'style') {
$scope.showOptions = true;
$scope.showItemOptions = false;
$scope.showOrderOptions = false;
}
else if (type == 'order') {
$scope.showOrderOptions = true;
$scope.showItemOptions = false;
$scope.showOptions = false;
}
}
}//end of if subdiv
else if (option == 'maindiv') {
if (!$scope.notMain) {
$scope.showItemOptions = false;
$scope.showOptions = false;
$scope.showOrderOptions = false;
}
$scope.notMain = false;
}//end of if maindiv
};
here is the html for just one of the drop downs (but they are all the same with different variables:
<div class="dropdownlistheader" ng-click="toggle('subdiv','order')">
<input type="text" readonly="readonly" class="dropdownlistinput" value="{{selectedOrderValuesDisplay}}" /> </div>
<div id="ddl123" ng-show="showOrderOptions" class="dropdownlist">
<div ng-show="showOrderOptions" ng-repeat="option in OrdersDDL">
<label> <input type="checkbox" ng-model="selected[$index]" ng-click="toggleOrderSelection(option.Number, option.Details)"> {{option.Details}}</label> </div></div>
I changed the whole thing to one function. was able to do it easily by changing the ng-show variables to contain the text of of the name of the ddl that should show instead of bool like they were.
$scope.toggle = function (option,type) {
if (option == 'subdiv') {
$scope.notMain = true;
if ($scope.notMain) {
$scope.showDDL = type;
}
}
else if (option == 'maindiv') {
if (!$scope.notMain) {
$scope.showDDL = '';
}
$scope.notMain = false;
}
};
in html: ng-show=="type" //type is hardcoded in html
I am a bit new to flash and actionscript but i am learning. With this code I am trying to get a message that says true when the value is between from and to. When I run this it gives the error in the title. What am I doing wrong?
from = Number(txtFra.text);
value = Number(txtTall.text);
to = Number(txtTil.text);
var from:Number;
var value:Number;
var value:Number;
function insideIntervall(from:int, value:int, to:int):Boolean
{
var bool:Boolean
if (from<value<to)
{
bool = true;
}
else
{
bool = false;
}
if (bool == true)
{
trace("True");
}
else
{
trace("False");
}
}
The error in the title is because your function must explicitly return a value. You do this with the keyword return.
However, there is another error in your program: you cannot compare from<value<to. What you need to check is that from < value && value < to. Basically, that both conditions are true.
The body of your function could then be simplified to: return from < value && value < to;