Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Regular Expression help (php) a-z0-9

Featured Replies

Hi all,

 

Think im close to figuring this one, but I keep messing and it is not working.

Basically I want the php to validate all strings as true if they are [:alnum:]. However, my script is only returning the last string as "1". (seems it only accepts 1 character strings). what amendment do I need to make to say the whole string (can be any string size) has to be [:alnum:]?

 

the Code:

<?php

function CharNum_RegExp_Validate($string){

$pattern = "^[:alnum:]+$";

if (eregi($pattern, $string)) {

return "1";

}else{

return "0";

}

}

echo CharNum_RegExp_Validate("string01");

echo CharNum_RegExp_Validate("string.01");

echo CharNum_RegExp_Validate("1string");

echo CharNum_RegExp_Validate("string01^");

echo CharNum_RegExp_Validate("a");

?>

 

The Result: 00001

The Wanted Result: 10101

  • Author

I know that we are not meant to bump, but kinda been waiting quite a while for this one... and I need the answer like ASAP!.

 

...bump!

  • Author

Topic Resolved. For future referance for anyone visiting this thread.... fix:

 

 

function alnum_validate($string){

if (ctype_alnum($string)){

return "1";

}else{

return "0";

}

}

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.