Import csv to phpmyadmin

Updated 29/01/2021 Simple but can cause lots of problems. I have one column with 200,000 postcode entries! in a CSV file. One Tab. Like below My first insert of 4000 was quick without error, but the 200,000 had import errors. I tried many Free CSV splitters online but all had problems except one! https://textfilesplitter.com/ So […]
Create a plugin with shortcode for Elementor – Most basic ever!

1. Save this code below as rawcode.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /** * Plugin Name: Rawcode Wodpress Plugin demo * Plugin URI: http://aq.gthex.co.uk:10000 * Description: Display content using a shortcode to insert in a page or post * Version: 0.1 * Text Domain: rawcode-wordpress-plugin-demo * Author: mike * Author URI: http://aq.gthex.co.uk:10000 */ function rawcode_wordpress_plugin_demo($atts) { echo "<h1>hello this is the rawcode plugin demo</h1>"; } add_shortcode('rawcode-plugin-demo', 'rawcode_wordpress_plugin_demo'); |
2. Create a folder in the plugins folder called the same – “rawcode” (\wp-content\plugins\rawcode) 3. This will now show up as a plugin. Activate it. 4. In a page or post within elementor (or without) add the following shortcode. [rawcode-plugin-demo] 5. It will now appear in the […]
Add how many left in stock on products stock controlled only – Woocommerce

I have 3 products in woocommerce that I wish to sell and show how many left in stock for each one. The rest of the website is not stock controlled. I do not want to show a label that says 745 in stock or whatever for all of them as they are always in stock. […]
Add a dropdown to Woocommerce Checkout Fields

To add a dropdown or select element to the fields on a woocommerce checkout, this can be achieved by the following code. Just add this code and amend where necessary to the functions.php file. Add dropdown
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// where found us //* Add select field to the checkout page add_action('woocommerce_before_order_notes', 'wps_add_select_checkout_field'); function wps_add_select_checkout_field( $checkout ) { echo '<br><br>'; woocommerce_form_field( 'myquestion', array( 'type' => 'select', 'class' => array( 'wps-drop' ), 'label' => __( 'How did you find out about us?' ), 'options' => array( 'blank' => __( 'Please Select', 'wps' ), 'google' => __( 'Search engine (Google etc)', 'wps' ), 'brochure' => __( 'Brochure', 'wps' ), 'recommedation' => __( 'Recommendation', 'wps' ) ) ), $checkout->get_value( 'myquestion' )); } |
Update dropdown
1 2 3 4 5 6 7 8 9 |
//* Update the order meta with field value add_action('woocommerce_checkout_update_order_meta', 'wps_select_checkout_field_update_order_meta'); function wps_select_checkout_field_update_order_meta( $order_id ) { if ($_POST['myquestion']) update_post_meta( $order_id, 'myquestion', esc_attr($_POST['myquestion'])); } |
Display dropdown answer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
//* Display field value on the order edition page add_action( 'woocommerce_admin_order_data_after_billing_address', 'wps_select_checkout_field_display_admin_order_meta', 10, 1 ); function wps_select_checkout_field_display_admin_order_meta($order){ echo '<p><strong>'.__('Found by').':</strong> ' . get_post_meta( $order->id, 'myquestion', true ) . '</p>'; } //* Add selection field value to emails add_filter('woocommerce_email_order_meta_keys', 'wps_select_order_meta_keys'); function wps_select_order_meta_keys( $keys ) { $keys['myquestion:'] = 'myquestion'; return $keys; } |
Change height of category quick edit box in Dashboard

To change the height of the quick edit category box add this code toy your functions.php page. It will add the CSS as the last command and you then can change the height instead of scrolling all day.
1 2 3 4 5 6 7 8 9 10 11 12 |
function change_cat_meta_postbox_css(){ ?> <style type="text/css"> .cat-checklist.product_cat-checklist { min-height: 900px; background-color: #b8d86a; } </style><?php } add_action('admin_head', 'change_cat_meta_postbox_css'); |
Align ‘Add to Cart’ product buttons – WooCommerce

This problem should be sorted by Woocommerce but they still have the problem. when you have to redesign a website that has weird image sizes and you cant really do much about that, you need to find a way to align all the buttons so they look neat. The only way I have found that […]
Award for the Worst Unsubscribe page 2021

Update 15/1/21: We have had to take back the award as they have updated there unsubscribe page! (I am pretty sure they will be OK about that!). This shows they respond to emails in a positive manner and the chain of command in a complaint gets to the correct people. Well done Rated People.There updated […]
How to find the last folder in url

If this is my url I am running the script in http://aq.gthex.co.uk:10000/webcontent/mylogin.php and I want to find the part called webcontent use the script below to find this part.
1 2 3 4 5 6 |
$path = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $array = explode('/',$path); $count = count($array); $actualurl = $array[$count-2]; |
The result will be: webcontent
Convert number to month name in PHP

1 2 3 4 5 6 |
$mymonth = "11"; echo date("F", strtotime(date("Y") ."-". $mymonth ."-01")); The result would be "November" |
How to catch errors and warnings in PHP

Catching errors and Warnings Below is a standard for catching errors. This would not work for warnings. That code is at the bottom.
1 2 3 4 5 6 7 8 9 10 |
try { print "this is our try block n"; throw new Exception(); } catch (Exception $e) { print "something went wrong, caught yah! n"; } finally { print "this part is always executed n"; } |
How to catch warnings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context) { throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line ); }, E_WARNING); try { // any code that may have a warning } //restore the previous error handler restore_error_handler(); |
Add a Favicon to your website

Add this code below to the header of your website. Then add the favicon (png) to the root of your website.
1 2 3 |
<link rel="icon" type="image/png" href="/fav.png" /> |
You can use .ico files by using the code below.
1 2 3 4 |
<link rel="shortcut icon" href="http://aq.gthex.co.uk:10000/favicon.ico" type="image/vnd.microsoft.icon"/> <link rel="icon" href="http://aq.gthex.co.uk:10000/favicon.ico" type="image/x-ico"/> |
Add this to your header.php file and add the image usually 16px x 16px in your root.
Enable GTmetrix Old Style Reports – December 2020

So GTmetrix.com thinks they have helped us, by creating a whole new version of their very good website testing site. Unfortunately they have not. They have just made it more difficult to find the results we are used to! Luckily I have found a switch within their settings that puts it all back the way […]
Free Share Code for Freetrade App

Buy & Sell Shares for FREE instantly Usually when you buy shares through a bank or building society like Halifax they charge you about £10 every time you buy some shares or sell them!!! Freetrade is free to buy and sell shares! USE THE LINKS BELOW https://magic.freetrade.io/join/mike/e307a29f HOW TO USE Use my link to join […]
How to remove “description” heading in product description? – WooCommerce

Woocommerce provides a couple of tabs such as Product Information, and Description. you may find under the tab it repeats which can look weird. to remove the duplicate wording use the code below in the functions file.php
1 2 3 4 5 6 7 8 9 10 11 |
// Remove the product description Title add_filter( 'woocommerce_product_description_heading', '__return_null' ); // Change the product description title add_filter('woocommerce_product_description_heading', 'change_product_description_heading'); function change_product_description_heading() { return __('NEW TITLE HERE', 'woocommerce'); } |
Adding Canonical link manually – PHP

if you have a hand coded site to help with your SEO you need a canonical link. Below is a PHP script that creates a canonical url link on page load. So this should answer your question of how to add canonical tag in PHP This is a self-referencing canonical link
1 2 3 4 5 6 7 8 9 |
<?php $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $canon = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; echo '<link rel="canonical" href="'.$canon.'">'; ?> |
Check if PHP array empty

1 2 3 4 5 |
if (empty($var)) { echo "The variable is empty"; } |
You can also use not empty, by adding an exclamation mark.
1 2 3 4 5 |
if (!empty($var)) { echo "The variable has something stored"; } |
Dropdown from MySql Select Query – Select

Creating a dropdown from a MySql query is quite easy There are a few ways, simplest is to create an array then just loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<select> <option selected="selected">Choose one</option> <?php // A sample animal array $animals = array("Dog", "Fish", "Rabbit", "Wolf"); // Iterating through the animals array foreach($animals as $item){ echo "<option value='strtolower($item)'>$item</option>"; } ?> </select> |
Another method without an array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php $sql = "select clientname,id from client group by clientname"; if(!$result = $mysqli->query($sql)){ die('There was an error running the query [' . $mysqli->error . ']'); } ?> <select id="siteclientname" name="siteclientname" class="form-control"> <?php echo "<option value=''>Choose</option>"; while($row = mysqli_fetch_array($result)) { echo "<option value='".$row['id']."'>".ucfirst($row['clientname'])."</option>"; } // echo "<option>New Client</option>"; ?> </select> |
Maybe pull three things…..
1 2 3 |
echo "<option value='" . $row['ID'] ."'>" . $row['client'] ." - ". $row['campaign'] ." - ". $row['ID'] ."</option>";} |
And for two dropdowns take a look here.
Auto Resize Dropdown to fit text – Select – Jquery

If you have ever had a dropdown text box that someone has added a very long option to, you will know that it can put your whole page design out. Using this method it the most easiest way. Just add it to your page and it will sort out all your select boxes in one […]
Get last part of url – page name

If you need to get the last part of a url of the page you are in, the code below will show you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $uri = $_SERVER['REQUEST_URI']; echo "<br>1".$uri; // Outputs: URI $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; echo "<br>2".$url; // Outputs: Full URL $query = $_SERVER['QUERY_STRING']; echo "<br>3".$query; // Outputs: Query String ?> |
1 2 3 4 |
$path = basename($_SERVER['HTTP_REFERER']); echo $path; |
Shows loop.php
Trim left Javascript text

Simple way to trim whitespace for the beginning of text using JavaScript.
1 2 3 4 |
var keywordvalue = " Hi "; var keywordvalue = (keywordvalue.trimLeft()); |
Output = “Hi ” To replace all whitespace using Javascript use this next script. http://aq.gthex.co.uk:10000/javascript/trim-whitespace-javascript/
Sweet Alert with textbox edit

After many hours of trying Sweet Alert, I have finally managed to add a textbox, and edit a variable. The magic part was inputValue: keywordid
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
var keywordid = $(this).attr('id'); Swal.fire({ title: "Sweet Alert Text Box", text: "Write something interesting:", input: 'text', inputValue: keywordid, showCancelButton: true }).then((result) => { if (result.value) { alert("Result: " +result.value); } }); |
Another version of this is the text area input with sweet alert This is supposed to be the way of adding text input but I never managed to make […]
Write many Arrays to a Database in one insert

This should really use foreach instead of counting the array, but it could come in handy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php // write many array to a database in one go require('../cmdataconn.inc'); $todo_item = array('dog','cat','fish','frog'); $todo_id = array(3,6,54,23); $howmany = (count($todo_id));// count array for ($i = 0; $i < $howmany; $i++) { echo "<br>Inserted".$i; $query = "INSERT INTO list1 (todo_id,todo_item) VALUES ('$todo_id[$i]', '$todo_item[$i]')"; if ($mysqli->query($query) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $sql->error; } } $rowcount=mysqli_num_rows($query); printf("Result set has %d rows.\n",$rowcount); ?> |
MySQL result as first in PHP Select Dropdown

This will show your result from saved data as the first in a dropdown of other results. On its first loop it will add something in the beginning, then add the rest.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
$sql = "SELECT * FROM clientskeywords WHERE myclientid=$clientid"; if(!$result = $mysqli->query($sql)){ die('There was an error running the query [' . $mysqli->error . ']'); } <select id="keyworddropdown" name="kdropdown" class="form-control"> <?php $kcount =0; while($row = mysqli_fetch_array($result)) { if ($row['keyword']!=""){ if ($kcount==0) { echo "<option value=".$row['keyword']." selected='selected'>".$keyword[$key]."</option>"; //only runs once } echo "<option value='".$row['id']."'>".$row['keyword']."</option>"; } $kcount=$kcount+1; } ?> </select> |
Refer to parent element from within ajax call – Jquery

If you use $(this) within the ajax code it will not find the element you need. Get the element at the beginning using (this) and create a variable of it. Then you can late refer to this variable in the ajax part.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<script> $(document).ready(function(){ // button click to go to client $(document).on('click', '.updateseotime', function() { var myblock = $(this).closest("td").find(".editseotime"); //get the part you want to refer to within ajax var clientid = $(this).attr('data-client'); $.ajax({ url: "update.php", dataType: "html", type: 'POST', data: "clientid="+clientid, success: function(data){ $(myblock).text("I will change"); //use new reference to change without using (this) } }); }); }); </script> |
Change Static loading Hourglass icon on Firefox 80

Does your Firefox loading icon now look like this? If you have used Firefox lately and your egg time/hourglass icon is now static when loading a web page then this will solve the problem and make it the nice loading animation you had previously. One switch is all you need. (only works for Windows). How […]
Sweet Alert text input and save to a database

The code below will save the input from Sweet Alert and save this to a database. You need to prepare the MySQL saving page (addpage.php) and collect post data ‘pagename’ I have added my sweet alert cdn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.28.2/sweetalert2.min.css"> <script src="//cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.28.2/sweetalert2.all.js"></script> <script> $(document).ready(function(){ $(document).on('click', '.addpage', function() { Swal.fire({ title: "NEW PAGE", text: "Add new page name below", input: 'text', showCancelButton: true }).then((result) => { if (result.value) { $.ajax({ url: "addpage.php", dataType: "html", type: 'POST', data: "pagename="+result.value, success: function(data){ alert(data); } }); //end ajax } //end if }); }); }); </script> |
Hope this works for you.
Website Shame Awards

If you are listed here then you need to work just that little bit harder. I can understand when you are doing a website yourself, you don’t have much time to devote to this. If you are one of the biggest companies in the world then maybe you should check your website maybe once or […]
Field “ssl certificate, ssl key” can not be blank.

If you have this error “Field “ssl certificate, ssl key” can not be blank.” then this is how you fix it. open file /usr/local/vesta/data/users/—user_name—/web.conf find “LETSENCRYPT” where you want reload LETSENCRYPT set “no” resave domain
Create a Random Password in Javascript

A simple way to create a random password in JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } alert(makeid(7)); |
How to Share your Google Analytics Account in 6 Steps

Step 1 Open your Google Analytics dashboard, and click the cog Step 2 Click Property User Management Step 3 Click the blue plus icon in top right Step 4 Click Add Users Step 5 and 6 Add the email of the person you wish to access Google Analtytics data, and then click Add
Resize gallery thumbnails to show only 3 – Woocommerce

I only have 2 or maybe 3 images per product but the gallery is expecting lots, so it sets out 4 columns, which makes my images very small. Therefore I need to have only 3 columns. The code below lets me set as many columns as I need.
1 2 3 4 5 |
.woocommerce div.product div.images .flex-control-thumbs li { width: 33.33%; } |
and now it looks like this…
How to Fix Blurry Gallery Thumbnails in Woocommerce

I had some really blurry gallery thumbnails in Woocommerce, using the Hello theme with Elementor. The images uploaded were of very high quality and so I read a few blog posts and found out about “Regenerate Thumbnails” plugin. So I thought I would give it a go. I installed then regenerated the thumbnails, and it […]
Change ‘Add to cart’ button to ‘View Product’ in Woocommerce

Changing the button text to read ‘View Product’ in Woocommerce In this case I have changed it to “Have a Look”…
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Replace add to cart button by a linked button to the product in Shop and archives pages add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 ); function replace_loop_add_to_cart_button( $button, $product ) { // Not needed for variable products if( $product->is_type( 'variable' ) ) return $button; // Button text here $button_text = __( "Have a Look", "woocommerce" ); return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>'; } |
How do I add the Widgets menu using “Hello Theme” for Elementor?

To enable the Widgets menu item in the WordPress admin menu, add the following code in your functions.php file
1 2 3 4 5 |
if (function_exists("register_sidebar")) { register_sidebar(); } |
You will then have the Widgets menu available to you, you can then assign Widgets to the Sidebar as usual in Appearance > Widgets. Note: This may cause a warning in WordPress 5.6. My local […]
Upload image with PHP – Simple

testupload.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<!DOCTYPE html> <html> <head> <title>Upload your files</title> </head> <body> <form enctype="multipart/form-data" action="target.php" method="POST"> <p>Upload your file</p> <input type="file" name="uploaded_file"></input><br /> <input type="submit" value="Upload"></input> </form> </body> </html> |
target.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?PHP if(!empty($_FILES['uploaded_file'])) { $path = "uploads/"; $path = $path . basename( $_FILES['uploaded_file']['name']); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) { echo "The file ". basename( $_FILES['uploaded_file']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } ?> |
Change default woocommerce myaccount text

If you want to change the default myaccount text that shows after login (“From your account dashboard you can view your recent orders etc), then editing the file within the woocommerce plugin will work, but you need to pay special attention to how this is done. If you just edit the file, when woocommerce is […]
Center a heading over an image using Elementor

To centre a heading using elementor can be very difficult, especially when tablet mode and mobile mode are transitioned to as the pixels away from the top and bottom change, therfore the heading moves. If you use a standard image, and underneath that add a heading. Then add the following code the CSS of the […]
Change Woocommerce checkout text – Coupon to Voucher

This code fully works, and unlike a few others codes the link to the checkout works. This is a mashup of snippets that works. add this to your functions.php file and it will find the word ‘Coupon’ and change it to ‘Voucher’.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
//change coupon to voucher - codehaven snippet add_filter( 'gettext', 'fix_woocommerce_strings', 999, 3 ); add_filter( 'gettext', 'bt_rename_coupon_field_on_cart', 10, 3 ); add_filter( 'woocommerce_coupon_error', 'bt_rename_coupon_label', 10, 3 ); add_filter( 'woocommerce_coupon_message', 'bt_rename_coupon_label', 10, 3 ); add_filter( 'woocommerce_cart_totals_coupon_label', 'bt_rename_coupon_label',10, 1 ); function bt_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) { // bail if not modifying frontend woocommerce text if ( is_admin() || 'woocommerce' !== $text_domain ) { return $translated_text; } if ( 'Coupon:' === $text ) { $translated_text = 'Voucher Code:'; } if ('Coupon has been removed.' === $text){ $translated_text = 'Voucher code has been removed.'; } if ( 'Apply coupon' === $text ) { $translated_text = 'Apply Voucher'; } if ( 'Coupon code' === $text ) { $translated_text = 'Voucher Code'; } return $translated_text; } function bt_rename_coupon_label( $err, $err_code=null, $something=null ){ $err = str_ireplace("Coupon","Voucher Code ",$err); return $err; } add_filter( 'woocommerce_checkout_coupon_message', 'bbloomer_have_coupon_message'); function bbloomer_have_coupon_message() { return '<i class="fa fa-ticket" aria-hidden="true"></i> Have a Voucher? <a href="#" class="showcoupon">Click here to enter your Voucher code</a>'; } |
Change ‘shipping’ to ‘delivery’ in Woocommerce

To replace the word shipping which is more American to delivery the code below will work for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
add_filter( 'woocommerce_shipping_package_name', 'custom_shipping_package_name' ); function custom_shipping_package_name( $name ) { return 'Delivery'; } function fix_woocommerce_strings( $translated, $text) { // STRING 1 $translated = str_ireplace( 'Shipping', 'Delivery charge', $translated ); return $translated; } add_filter( 'gettext', 'fix_woocommerce_strings', 999, 3 ); |
Password strength checker in jQuery

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
<!DOCTYPE html> <html> <head> <title>Password strength checker in jQuery - Demo Preview</title> <meta content="noindex, nofollow" name="robots"> <title>How to check password strength using jQuery</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> </head> <body> <div id="container"> <div id="header"> <h2>Password Strength Checking with jQuery</h2> </div> <div id="content"> <form id="register" name="register"> <label for="password">Password :</label> <input id="password" name="password" type="password"> <span id="result"></span> </form> </div> </div> </body> </html> <script> $(document).ready(function() { $('#password').keyup(function() { $('#result').html(checkStrength($('#password').val())) }) function checkStrength(password) { var strength = 0 if (password.length < 6) { $('#result').removeClass() $('#result').addClass('short') return 'Too short' } 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 // 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' } } }); </script> <style> body{ margin:0; padding:0; background:#CCC repeat; font-family:'Vollkorn',serif,Arial; font-size:15px; line-height:1.5 } #container{ width:600px; margin:0 auto; background:#fff; padding:20px } #header{ text-align:center; margin:20px 0 40px } #register{ margin-left:100px } #register label{ margin-right:5px } #register input{ padding:5px 7px; border:1px solid #d5d9da; box-shadow:0 0 5px #e8e9eb inset; width:250px; font-size:1em; outline:0 } #register .short{ font-weight:700; color:red } #register .weak{ font-weight:700; color:orange } #register .good{ font-weight:700; color:#2D98F3 } #register .strong{ font-weight:700; color:#32cd32 } </style> |