Smarty IF Function: preg_match
Posted by Mark [Elevated X Support], Last modified by Mark [Elevated X Support] on 01 May 2014 04:52 PM

Description:

Searches the string for a match based on a regular expression.


if (preg_match($[regex], $[string]))

Smarty Example:

{assign var="a" value="alpha"}
{assign var="b" value="1023"}

{if preg_match("/[a-z]/", $a)}
The string {$a} contains characters a-z
{else}
The string {$a} contains does not contain characters a-z
{/if}
<BR>
{if preg_match("/[a-z]/", $b)}
The string {$b} contains characters a-z
{else}
The string {$b} contains does not contain characters a-z
{/if}

Output:

The string alpha contains characters a-z
The string 1023 contains does not contain characters a-z

(19 vote(s))
Helpful
Not helpful

Comments (0)