Monday, September 5, 2022

Sunday, August 7, 2022

Restrict an HTML input text box to allow only numeric values

1. Using <input type="number">

<label for="salary">Enter your salary:</label>
<input type="number" id="salary" name="salary">

2. Using pattern attribute

<label for="salary">Enter your salary:</label>
<input type="text" id="salary" name="salary" pattern="[0-9]+">

3. Using oninput event

<label for="salary">Enter your salary:</label>
<input type="text" id="salary" name="salary"
    oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" />

Tuesday, November 30, 2021

Memproteksi Image di Website Anda agar Tidak Ditampilkan di Website Lain

RewriteEngine on
RewriteCond %{REQUEST_URI} !dilarang-hotlink\.jpg$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?nama_domain\.com [NC]
RewriteRule \.(jpe?g|png|gif)$ /wp-content/uploads/2017/05/dilarang-hotlink.jpg [NC,L]

Monday, November 29, 2021

WHERE Clause to find all records in a specific month

id postdate
-- ----------------
1  2020-01-01 12:08
2  2020-02-01 12:00
3  2020-01-12 09:40
4  2020-01-29 17:55
SELECT id FROM `myPost` 
   WHERE MONTH(postDate) = 1 AND YEAR(postDate) = 2020

Friday, September 17, 2021

Menghapus catatan Sebelum Tanggal Tertentu

//menghapus semua data dari sebelum 1 hari
SELECT * FROM Orders WHERE OrderDate < DATE_SUB("1996-10-03", INTERVAL 10 DAY);
SELECT * FROM Orders WHERE OrderDate < DATE_SUB(NOW(), INTERVAL 10 DAY);

//menghapus semua data dari sebelum 1 bulan
SELECT * FROM Orders WHERE OrderDate < DATE_SUB("1996-10-03", INTERVAL 1 MONTH);

Wednesday, September 8, 2021

React Native - CSS :last-child without a border?

return books.map((book, i) => {
  return(
    <View style={ (i === books.length - 1) ? styles.noBorderBook : styles.book} key={i}>
      <Text style={(i === books.length - 1) ? styles.noBorderBook : styles.book}>{book.title}</Text>
    </View>
  );
});