P
P
Pit2019-12-02 14:44:37
WordPress
Pit, 2019-12-02 14:44:37

How to check inputMask field for empty value?

There is an input field with the InputMask plugin connected, I need to check the field, if the field is empty or the required number of digits are not entered, then remove the focus class. If you entered the required number of digits, then add the focus class.

At this stage, the script works for me, with focus in the field, the hint rises, if the field is empty, the hint falls back. The problem is that when you enter 1 number in the field with the phone number, where the plugin works, the hint remains at the top. Since the field automatically removes 1 digit if you left the input field.

Sample script and additional code of mine:

https://codepen.io/pit6262/pen/ZEYEBbZ

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan Hasanli, 2018-12-15
@azerphoenix

Hello!
Pretty good resource for doing what you want:
https://www.smashingmagazine.com/2016/03/advanced-...
It's possible that there are ready-made plugins... For example, there is a filtering plugin for the woocomer
https:/ /ru.wordpress.org/plugins/woocommerce-produ...
https://ru.wordpress.org/plugins/yith-woocommerce-...

D
DENIS Kokorev, 2019-12-02
@pit6262

.blur(function(){
    var label = $(this).prev('.label');
    var value = $(this).val();
    var full = value.replace(/\+7\(\d{3}\) \d{3} \d{4}/g, "")=="" ? true: false;

    if(value == '' || !full){
      label.stop().css({ 'top': '1rem', });
      $(this).parent().removeClass('focus')
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question