Monday, October 9, 2017

format numbers with 00 prefixes in php?

 Is there any function to have numbers with 5 digit as
 00001, or
this number should be not random but have to increase the value of a previous field.


$n2 = str_pad($n + 1, 5, 0, STR_PAD_LEFT);

Use str_pad() by adding 0s (third parameter) to the left (fourth parameter) of the old number $n incremented by 1 (first parameter) until the length is 5 (second parameter).

Wednesday, August 23, 2017

Only number will taken in text box using javascript

if you want only number will be taken in the text box. so we will use this formet for javascript.

$(document).on('keyup','.numbersOnly', function() {
     this.value = this.value.replace(/[^0-9\.]/g,'');

Sunday, May 14, 2017

How to get the taxonomy values of a custom post type

If we want to fetch the taxonomy term of a specific post then we could do that.

$terms = get_the_terms( $post->ID, 'publication_category' );
if ($terms) {
    foreach($terms as $term) {
      echo $term->name;

in this function 
$post->ID :- Your post id. 
 'publication_category'  - its a taxonomy name.

Sunday, May 7, 2017

html 5 password validation

<input id="password" name="password" type="password" pattern="^\S{6,}$" 
onchange="this.setCustomValidity(this.validity.patternMismatch ? 
'Must have at least 6 characters' : ''); if(this.checkValidity()) 
form.password_two.pattern = this.value;" placeholder="Password" required>

<input id="password_two" name="password_two" type="password" 
pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 
'Please enter the same Password as above' : '');" placeholder="Verify Password" required>

Monday, May 1, 2017

How can you check for a #hash in a URL using JavaScript?

if we are using ajax and on the response we want to know the url has # or not. so by this code we can find it it have the # on the url or not.

Method 1:-
if(window.location.hash) {
  // Fragment exists
} else {
  // Fragment doesn't exist

Method 2:-
if (location.href.indexOf("#") != -1) {
        // Your code in here accessing the string like this
        // location.href.substr(location.href.indexOf("#"))

Method 3:-

var url = '',
    hash = url.split('#')[1];

if (hash) {
} else {
    // do something else

Method 4:-
var requestedHash = ((window.location.hash.substring(1).split("#",1))+"?").split("?",1);