A
A
Alex Ivanov2018-03-05 19:08:11
JavaScript
Alex Ivanov, 2018-03-05 19:08:11

How to find an occurrence of text from the beginning of a string?

They set me an interesting task, which I can’t cope with - first I had to find the occurrence of the text in the text field, I did:

$(document).ready(function(){
    $("#Editortextarea").bind('propertychange change input paste', function() {
       		
      var MesText = $('#Editortextarea').val();
      
      if((MesText.indexOf('quote') > 0 ) || (MesText.indexOf('QUOTE') > 0 ))
      	{
 				 alert('есть');
      } 
      else
      {
                        	alert('нет');
      }
    });
    });

But now it is necessary that a check is also performed for the beginning of the text with
[b]text{3,15}[/b],

those. whether at the beginning of the text there is an appeal in [b] tags with a length of 3 to 15 characters. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bhudh, 2018-03-05
@Protossan

if((MesText.indexOf('quote') > 0 ) || (MesText.indexOf('QUOTE') > 0 ))

can be replaced by checked the same way:if(/quote/gi.test(MesText))
if( /^\[b\].{3,15}\[\/b\],/.test(MesText) )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question