Note that there are some explanatory texts on larger screens.

plurals
  1. POPreg match and Preg replace specific format
    primarykey
    data
    text
    <p>I need help with preg match/replace forma i really cant understand how its working and what each element doing.</p> <p>So far I have this:</p> <pre><code>$username = preg_replace('/\s+/', '_', $_POST['uname']); if(preg_match('/^[a-zA-Z0-9]{5,12}+$/u', $username)) { $username = trim(strip_tags(ucfirst($purifier-&gt;purify(@$_POST["uname"])))); } else { $message['uname']='wrong username input'; } </code></pre> <p>And for utf8(hebrew language) i got this:</p> <pre><code>if(preg_match("/^[\p{Hebrew} a-zA-Z0-9]{2,10}+$/u", $_POST['fname'])) { // } </code></pre> <p>which is working perfect, but I don't want to allow Hebrew on username just English.</p> <p>I tried to play with that in multiple combinations, I tried to change but no success, and I did research on StackOverflow and Google but can't make it like I want I don't understand. I used a RegEx site to and tried to build but with no success.</p> <p>So until now I got this :</p> <p>User can put 5-12 letters/numbers no special characters.</p> <p>What i want is :</p> <ul> <li>Can enter between 5-12 letters/numbers no special charcaters - i already have it.</li> <li>Allow whitespaces </li> <li><code>preg_match</code> if no mixed language's like E.G: $username = שדגדשsdsd; &lt;- not allowed mixed languages.</li> </ul> <p>And <code>preg_replace</code> to:</p> <ul> <li>Replace white spaces to nothing (remove white spaces) i have this but i dont know if it correct:</li> </ul> <p><code>$username = preg_replace('/\s+/', '', $_POST['uname']);</code></p> <p>Also, I am using UTF-8 language .</p> <p><strong>EDIT:</strong></p> <p>With help of hwnd , i make it to work like i want the latest code:</p> <pre><code> if(preg_match('/^[\p{Hebrew}]{2,10}|[a-zA-Z]{2,10}$/u', $_POST['fname']) &amp;&amp; preg_match('/^[a-zA-Z]{2,10}|[\p{Hebrew}]{2,10}$/u', $_POST['fname'])) { $message = 'valid'; }else{ $message = 'Invalid'; } </code></pre> <p><strong>Solved</strong>,Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload