Михаиллл
МихаилллApril 4, 2020, 5:20 p.m.

Как в QML в if использовать регулярное выражение

Добрый день.
Как в QML в if использовать регулярное выражение ?
Мне нужно проверить, является ли текст почтой.
Нашел такое выражение, но не знаю как его использовать

 '/^((([0-9A-Za-z]{1}[-0-9A-z\.]{1,}[0-9A-Za-z]{1})|([0-9А-Яа-я]{1}[-0-9А-я\.]{1,}[0-9А-Яа-я]{1}))@([-0-9A-Za-z]{1,}\.){1,2}[-A-Za-z]{2,})$/u'
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

4
t
  • April 4, 2020, 6:49 p.m.

https://doc.qt.io/qt-5/qml-qtquick-regularexpressionvalidator.html
https://doc.qt.io/qt-5/qtquick-input-textinput.html

QML parses JavaScript regular expressions:

https://www.w3schools.com/js/js_regexp.asp
https://www.w3schools.com/jsref/jsref_obj_regexp.asp

    Михаиллл
    • April 5, 2020, 2:09 a.m.

    Попоробовал сделать как в примере, но получаю ошибку: Ожидается лексема «;»

    TextInput {
        id: hexNumber
        validator: RegularExpressionValidator { regularExpression: /[0-9A-F]+/ }
    }
    
      Михаиллл
      • April 5, 2020, 2:25 a.m.

      А так работает, но если помещаю туда выражение для электронной почты, то ничего не происходит

      validator: RegExpValidator { regExp: /[0-9A-F]+/ }
      
        Михаиллл
        • April 5, 2020, 2:35 a.m.
        • The answer was marked as a solution.

        Так работает

                console.log(textEmail.text)
                var str = textEmail.text;
                var n = str.search(/^((([0-9A-Za-z]{1}[-0-9A-z\.]{1,}[0-9A-Za-z]{1})|([0-9А-Яа-я]{1}[-0-9А-я\.]{1,}[0-9А-Яа-я]{1}))@([-0-9A-Za-z]{1,}\.){1,2}[-A-Za-z]{2,})$/u);
                console.log(n)
                if(n == 0){
                    console.log("normal mail")
                }
        

          Comments

          Only authorized users can post comments.
          Please, Log in or Sign up
          AD

          C ++ - Test 004. Pointers, Arrays and Loops

          • Result:50points,
          • Rating points-4
          m

          C ++ - Test 004. Pointers, Arrays and Loops

          • Result:80points,
          • Rating points4
          m

          C ++ - Test 004. Pointers, Arrays and Loops

          • Result:20points,
          • Rating points-10
          Last comments
          i
          innorwallNov. 12, 2024, 9:12 a.m.
          Django - Tutorial 055. How to write auto populate field functionality Freckles because of several brand names retin a, atralin buy generic priligy
          i
          innorwallNov. 12, 2024, 5:23 a.m.
          QML - Tutorial 035. Using enumerations in QML without C ++ priligy cvs 24 Together with antibiotics such as amphotericin B 10, griseofulvin 11 and streptomycin 12, chloramphenicol 9 is in the World Health Organisation s List of Essential Medici…
          i
          innorwallNov. 12, 2024, 2:50 a.m.
          Qt/C++ - Lesson 052. Customization Qt Audio player in the style of AIMP It decreases stress, supports hormone balance, and regulates and increases blood flow to the reproductive organs buy priligy online safe Promising data were reported in a PDX model re…
          i
          innorwallNov. 12, 2024, 1:19 a.m.
          Heap sorting algorithm The role of raloxifene in preventing breast cancer priligy precio
          i
          innorwallNov. 12, 2024, 12:55 a.m.
          PyQt5 - Lesson 006. Work with QTableWidget buy priligy 60 mg 53 have been reported by Javanovic Santa et al
          Now discuss on the forum
          i
          innorwallNov. 12, 2024, 7:56 a.m.
          добавить qlineseries в функции buy priligy senior brother Chu He, whom he had known for many years
          i
          innorwallNov. 11, 2024, 9:55 p.m.
          Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
          9
          9AnonimOct. 25, 2024, 7:10 p.m.
          Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…

          Follow us in social networks