Wednesday 17 April 2019

Passing php array into javascript variable


<?php
// php array
$fruits = array('apple', 'orange', 'mango', 'banana', 'strawberry');
?>

<script type="text/javascript">
// use php implode function to build string for JavaScript array literal
var fruits = <?php echo '["' . implode('", "', $fruits) . '"]' ?>;
// ["apple", "orange", "mango", "banana", "strawberry"]
</script>
source : 

https://www.dyn-web.com/tutorials/php-js/array.php

Tuesday 16 April 2019

regex tester

script :

var paragraph = '222323';
var regex = '[0-9]{3,}'; //with at least 3 and above digits
var found = paragraph.match(regex);
console.log(found);
//which return back the array of numbers
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match

Postcode validation

https://stackoverflow.com/questions/17920096/php-validation-1st-line-of-address-and-postcode