Jump to content
  • 0

How to check if there is a special character in input


Question

Posted

Hello is there a way to check if there is a special character in input ? I tried "If (compare())" condition . Can you give me idea how properly check if there is a special character with in input

2 answers to this question

Recommended Posts

  • 0
Posted

Try using

*preg_match(<regular expression pattern>,<string>{,<offset>})

Searches a string for a match to the regular expression provided. The
offset parameter indicates the index of the string to start searching.
Returns offsets to captured substrings, or 0 if no match is found.

This command is only available if the server is compiled with the regular
expressions library enabled.

 

Something like this could work:

if (preg_match("^[a-zA-Z0-9]+$",.@yourString$)
{
	// This means it found a coincidence, meaning that no symbols where fund
}
else
{
	// No matches, symbols where found
}

 

  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...