Programming

preg_match for Japanese forms

郵便番号 /^[0-9]{3}-[0-9]{4}$/ if (preg_match(‘/^[0-9]{3}-[0-9]{4}$/’, $str)) { 電話番号 /^[0-9]{2,4}-[0-9]{2,4}-[0-9]{3,4}$/ if (preg_match(‘/^[0-9]{2,4}-[0-9]{2,4}-[0-9]{3,4}$/’, $str)) { Emailアドレス |^[0-9a-z_./?-]+@([0-9a-z-]+\.)+[0-9a-z-]+$| if (preg_match(‘|^[0-9a-z_./?-]+@([0-9a-z-]+\.)+[0-9a-z-]+$|’, $str)) { 全角空白のトリム /^ *(.*?) *$/u $str = preg_replace(‘/^ *(.*?) *$/u’, ‘$1’, $str); 半角+全角空白のトリム /^[\s ]*(.*?)[\s ]*$/u $str = preg_replace(‘/^[\s ]*(.*?)[\s ]*$/u’, ‘$1’, $str);

Posted in etc | Comments Off on preg_match for Japanese forms

When Chrome fails to load resource

Failed to load resource: net::ERR_CACHE_MISS Check Disable DirectWrite(Windows) at chrome://flags if the website has a multibyte character.

Posted in etc | Comments Off on When Chrome fails to load resource

Use a bracket in CSS

To control multiple class names in css. input[readonly=’readonly’] { display:none; }; .views-field[class*=’views-field-view’] { display:block; }input[readonly=’readonly’] { display:none; }; .views-field[class*=’views-field-view’] { display:block; }

Posted in CSS | Comments Off on Use a bracket in CSS

Unlimited cardinality pre-populate fields

I am trying to solve this and my only issue is that I want to keep this field as unlimited cardinality with fields in Field Collection already displayed to the user when they create the other reference node. function module_form_alter(&$form, &$form_state, $form_id) { if($form_id == ‘form_name’) { $reference_query = new EntityFieldQuery(); $reference_query->entityCondition(’entity_type’, ‘node’) ->entityCondition(’bundle’, ‘reference’) ->propertyOrderBy(’created’, ‘DESC’) ->range(0, 1); $reference_result = $reference_query->execute(); $reference_nid = array_keys($reference_result[’node’]); $reference_refer = node_load($reference_nid);   $items_count = count($reference_refer->field_field_name[’und’]); $field_name = ‘field_field_name’; $form_theme = $form[$field_name][’und’][’#theme’]; // Remove delete and add more buttons $form[$field_name][’und’][0][’remove_button’][’#access’] = FALSE; $form[$field_name][’und’][’add_more’][’#access’] = FALSE; $items = &$form_state[’field’][$field_name][’und’];   if ($items_count > 1 and $items[’items_count’] != $items_count) { $items[’items_count’] = $items_count; $items[’field’][’cardinality’] = $items_count; […]

Tags:

Posted in Drupal | Comments Off on Unlimited cardinality pre-populate fields

Align float center

Sometimes float-left or float-right cannot make a center align and we can use a margin with Width but there is a simple way as below. #test { float: right; position: relative; left: -50%; }   #test li { float: left; position: relative; left: 50%; border: 1px solid red; }#test { float: right; position: relative; left: -50%; } #test li { float: left; position: relative; left: 50%; border: 1px solid red; } <ul id="test"> <li>red</li> <li>yellow</li> <li>white</li> <li>blue</li> <li>black</li> </ui><ul id="test"> <li>red</li> <li>yellow</li> <li>white</li> <li>blue</li> <li>black</li> </ui>

Posted in CSS | Comments Off on Align float center

REGEX

. $string1 = "Hello World\n"; if ($string1 =~ m/…../) { print "$string1 has length >= 5\n"; } ( ) $string1 = "Hello World\n"; if ($string1 =~ m/(H..).(o..)/) { print "We matched ‘$1’ and ‘$2’\n"; } Output: We matched ‘Hel’ and ‘o W’; + $string1 = "Hello World\n"; if ($string1 =~ m/l+/) { print "There are one or more consecutive letter \"l\"’s in $string1\n"; } Output: There are one or more consecutive letter "l"’s in Hello World ? $string1 = "Hello World\n"; if ($string1 =~ m/H.?e/) { print "There is an ‘H’ and a ‘e’ separated by "; print "0-1 characters (Ex: He Hoe)\n"; } ? $string1 = "Hello World\n"; if […]

Posted in PHP | Comments Off on REGEX

Japanese Hankaku

function checkhalf(str){ str = str; chkstr = escape(str.value); if (chkstr.indexOf(’%’) != -1){ alert(’入力は半角英数字でお願いします。’); str.value = ""; str.focus(); } }function checkhalf(str){ str = str; chkstr = escape(str.value); if (chkstr.indexOf(‘%’) != -1){ alert(‘入力は半角英数字でお願いします。’); str.value = ""; str.focus(); } }

Posted in jQuery, Javascript | Comments Off on Japanese Hankaku